本文整理匯總了Python中retriever.lib.models.Table.pk方法的典型用法代碼示例。如果您正苦於以下問題:Python Table.pk方法的具體用法?Python Table.pk怎麽用?Python Table.pk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類retriever.lib.models.Table
的用法示例。
在下文中一共展示了Table.pk方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: download
# 需要導入模塊: from retriever.lib.models import Table [as 別名]
# 或者: from retriever.lib.models.Table import pk [as 別名]
def download(self, engine=None, debug=False):
Script.download(self, engine, debug)
reload(sys)
if hasattr(sys, 'setdefaultencoding'):
sys.setdefaultencoding("utf-8")
self.engine.download_file(self.urls["GWDD"], "GlobalWoodDensityDatabase.xls")
filename = os.path.basename("GlobalWoodDensityDatabase.xls")
book = xlrd.open_workbook(self.engine.format_filename(filename))
sh = book.sheet_by_index(1)
rows = sh.nrows
# Creating data files
file_path = self.engine.format_filename("gwdd_data.csv")
gwdd_data = open_fw(file_path)
csv_writer = open_csvw(gwdd_data)
csv_writer.writerow(["Number", "Family", "Binomial", "Wood_Density", "Region", "Reference_Number"])
for index in range(1, rows):
row = sh.row(index)
# get each row and format the sell value.
row_as_list = [to_str(column_value.value) for column_value in row]
csv_writer.writerow(row_as_list)
gwdd_data.close()
table = Table("data", delimiter=",")
table.columns = [("Number", ("pk-int",)),
("Family", ("char",)),
("Binomial", ("char",)),
("Wood_Density", ("double",)),
("Region", ("char",)),
("Reference_Number", ("int",))]
table.pk = 'Number'
table.contains_pk = True
self.engine.table = table
self.engine.create_table()
self.engine.insert_data_from_file(engine.format_filename(file_path))
# Creating reference tale file
file_path = self.engine.format_filename("gwdd_ref.csv")
ref_file = open_fw(file_path)
csv_writerd = open_csvw(ref_file)
csv_writerd.writerow(["Reference_Number", "Reference"])
sh = book.sheet_by_index(2)
rows = sh.nrows
for index in range(1, rows):
row = sh.row(index)
# get each row and format the sell value.
row_as_list = [to_str(column_value.value, object_encoding=sys.stdout) for column_value in row]
csv_writerd.writerow(row_as_list)
ref_file.close()
table = Table("reference", delimiter=",")
table.columns = [("Reference_Number", ("pk-int",)), ("Reference", ("char",))]
table.pk = 'Reference_Number'
table.contains_pk = True
self.engine.table = table
self.engine.create_table()
self.engine.insert_data_from_file(engine.format_filename(file_path))
return self.engine
示例2: download
# 需要導入模塊: from retriever.lib.models import Table [as 別名]
# 或者: from retriever.lib.models.Table import pk [as 別名]
#.........這裏部分代碼省略.........
if len(this_line["species"]) < 3:
if len(this_line["genus"]) < 3:
id_level = "family"
else:
id_level = "genus"
else:
id_level = "species"
full_id = 1
tax.append((this_line["family"],
this_line["genus"],
this_line["species"],
id_level,
str(full_id)))
except:
raise
pass
tax = sorted(tax, key=lambda group: group[0] + " " + group[1] + " " + group[2])
unique_tax = []
tax_dict = {}
tax_count = 0
# Get all unique families/genera/species
print("\n")
for group in tax:
if not (group in unique_tax):
unique_tax.append(group)
tax_count += 1
tax_dict[group[0:3]] = tax_count
if tax_count % 10 == 0:
msg = "Generating taxonomic groups: " + str(tax_count) + " / " + str(TAX_GROUPS)
sys.stdout.flush()
sys.stdout.write(msg + "\b" * len(msg))
print("\n")
# Create species table
table = Table("species", delimiter=",")
table.columns=[("species_id" , ("pk-int",) ),
("family" , ("char", ) ),
("genus" , ("char", ) ),
("species" , ("char", ) ),
("id_level" , ("char", 10) ),
("full_id" , ("int",) )]
data = [[str(tax_dict[group[:3]])] + ['"%s"' % g for g in group]
for group in unique_tax]
table.pk = 'species_id'
table.contains_pk = True
self.engine.table = table
self.engine.create_table()
self.engine.add_to_table(data)
# Create stems table
table = Table("stems", delimiter=",")
table.columns=[("stem_id" , ("pk-auto",) ),
("line" , ("int",) ),
("species_id" , ("int",) ),
("site_code" , ("char", 12) ),
("liana" , ("char", 10) ),
("stem" , ("double",) )]
stems = []
counts = []
for line in lines:
try:
liana = line["liana"]
except KeyError:
liana = ""
species_info = [line["line"],
tax_dict[(line["family"],
line["genus"],
line["species"])],
line["site"],
liana
]
try:
counts.append([value for value in species_info + [line["count"]]])
except KeyError:
pass
for i in line["stems"]:
stem = species_info + [str(i)]
stems.append(stem)
self.engine.table = table
self.engine.create_table()
self.engine.add_to_table(stems)
# Create counts table
table = Table("counts", delimiter=",", contains_pk=False)
table.columns=[("count_id" , ("pk-auto",) ),
("line" , ("int",) ),
("species_id" , ("int",) ),
("site_code" , ("char", 12) ),
("liana" , ("char", 10) ),
("count" , ("double",) )]
self.engine.table = table
self.engine.create_table()
self.engine.add_to_table(counts)
return self.engine
示例3: download
# 需要導入模塊: from retriever.lib.models import Table [as 別名]
# 或者: from retriever.lib.models.Table import pk [as 別名]
#.........這裏部分代碼省略.........
else:
id_level = "genus"
else:
id_level = "species"
full_id = 1
tax.append((this_line["family"],
this_line["genus"],
this_line["species"].lower().replace('\\', '').replace('"', ''),
id_level,
str(full_id)))
except:
raise
pass
tax = sorted(tax, key=lambda group: group[0] + " " + group[1] + " " + group[2])
unique_tax = []
tax_dict = dict()
tax_count = 0
# Get all unique families/genera/species
for group in tax:
if not (group in unique_tax):
unique_tax.append(group)
tax_count += 1
tax_dict[group[0:3]] = tax_count
if tax_count % 10 == 0:
msg = "Generating taxonomic groups: " + str(tax_count) + " / " + str(TAX_GROUPS)
sys.stdout.write(msg + "\b" * len(msg))
print "Generating taxonomic groups: " + str(TAX_GROUPS) + " / " + str(TAX_GROUPS)
# Create species table
table = Table("species", delimiter=",")
table.columns=[("species_id" , ("pk-int",) ),
("family" , ("char", ) ),
("genus" , ("char", ) ),
("species" , ("char", ) ),
("id_level" , ("char", 10) ),
("full_id" , ("bool",) )]
data = [','.join([str(tax_dict[group[:3]])] + ['"%s"' % g for g in group])
for group in unique_tax]
table.pk = 'species_id'
table.contains_pk = True
self.engine.table = table
self.engine.create_table()
self.engine.add_to_table(data)
# Create stems table
table = Table("stems", delimiter=",", contains_pk=False)
table.columns=[("stem_id" , ("pk-auto",) ),
("line" , ("int",) ),
("species_id" , ("int",) ),
("site_code" , ("char", 12) ),
("liana" , ("char", 10) ),
("stem" , ("double",) )]
stems = []
counts = []
for line in lines:
try:
liana = line["liana"]
except KeyError:
liana = ""
species_info = [line["line"],
示例4: download
# 需要導入模塊: from retriever.lib.models import Table [as 別名]
# 或者: from retriever.lib.models.Table import pk [as 別名]
def download(self, engine=None, debug=False):
Script.download(self, engine, debug)
self.engine.download_file(self.urls["GWDD"], "GlobalWoodDensityDatabase.xls")
filename = os.path.basename("GlobalWoodDensityDatabase.xls")
book = xlrd.open_workbook(self.engine.format_filename(filename))
sh = book.sheet_by_index(1)
rows = sh.nrows
#Creating data table
lines = []
for i in range(1, rows):
row = sh.row(i)
if not all(Excel.empty_cell(cell) for cell in row):
this_line = {}
def format_value(s):
s = Excel.cell_value(s)
return str(s).title().replace("\\", "/").replace('"', '')
for num, label in enumerate(["Number", "Family", "Binomial", "Wood_Density",
"Region", "Reference_Number"]):
this_line[label] = format_value(row[num])
lines.append(this_line)
table = Table("data", delimiter="\t")
table.columns=[("Number" , ("pk-int",) ),
("Family" , ("char",) ),
("Binomial" , ("char",) ),
("Wood_Density" , ("double",) ),
("Region" , ("char",) ),
("Reference_Number" , ("int",) )]
table.pk = 'Number'
table.contains_pk = True
gwdd = []
for line in lines:
gwdd_data = [line["Number"],
line["Family"],
line["Binomial"],
line["Wood_Density"],
line["Region"],
line["Reference_Number"]]
gwdd.append(gwdd_data)
data = ['\t'.join(gwdd_line) for gwdd_line in gwdd]
self.engine.table = table
self.engine.create_table()
self.engine.add_to_table(data)
#Creating reference table
lines = []
sh = book.sheet_by_index(2)
rows = sh.nrows
for i in range(1, rows):
row = sh.row(i)
if not all(Excel.empty_cell(cell) for cell in row):
this_line = {}
def format_value(s):
s = Excel.cell_value(s)
return str(s).title().replace("\\", "/").replace('"', '')
for num, label in enumerate(["Reference_Number", "Reference"]):
this_line[label] = format_value(row[num])
lines.append(this_line)
table = Table("reference", delimiter="\t")
table.columns=[("Reference_Number" , ("pk-int",) ),
("Reference" , ("char",) )]
table.pk = 'Reference_Number'
table.contains_pk = True
gwdd = []
for line in lines:
gwdd_ref = [line["Reference_Number"],
line["Reference"]]
gwdd.append(gwdd_ref)
data = ['\t'.join(gwdd_line) for gwdd_line in gwdd]
self.engine.table = table
self.engine.create_table()
self.engine.add_to_table(data)
return self.engine