Skip to content

Commit

Permalink
Merge branch 'fast-table' of https://github.com/usc-isi-i2/t2wml into…
Browse files Browse the repository at this point in the history
… fast-table
  • Loading branch information
ChanaChelem committed Aug 12, 2021
2 parents ab526e8 + 0f88c6e commit fef84a5
Show file tree
Hide file tree
Showing 7 changed files with 7,958 additions and 199 deletions.
6 changes: 4 additions & 2 deletions backend/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ def get_calc_params(project, data_required=True, mapping_type=None, mapping_file
return None

start_end_kwargs = {}
for key in ["data_start", "map_start", "part_start"]:
for key in ["data_start", "map_start"]:#, "part_start"]:
start_end_kwargs[key] = int(request.args.get(key, 0))
for key in ["data_end", "map_end"]:
end = int(request.args.get(key, 0))
if end == 0:
end = None
start_end_kwargs[key] = end
start_end_kwargs["part_end"] = int(request.args.get("part_end", 30))

#start_end_kwargs["part_end"] = int(request.args.get("part_end", 30))
start_end_kwargs["part_count"] = int(request.args.get("part_count", 100))

calc_params = CalcParams(
project, data_file, sheet_name, **start_end_kwargs)
Expand Down
4 changes: 3 additions & 1 deletion backend/calc_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

class CalcParams:
def __init__(self, project, data_path, sheet_name, yaml_path=None, annotation_path=None,
data_start=0, data_end=None, map_start=0, map_end=None, part_start=0, part_end=None):
data_start=0, data_end=None, map_start=0, map_end=None,
part_start=0, part_end=None, part_count=100):
self.project = project
self.project_path = project.directory
self._data_path = data_path
Expand All @@ -21,6 +22,7 @@ def __init__(self, project, data_path, sheet_name, yaml_path=None, annotation_pa
self.map_end=map_end
self.part_start=part_start
self.part_end=part_end
self.part_count=part_count


@property
Expand Down
7 changes: 3 additions & 4 deletions backend/causx/causx_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,8 @@ def df_to_table(df, columns):


@error_with_func
def get_causx_partial_csv(calc_params, start=0, end=150):
start = calc_params.part_start
end = calc_params.part_end
def get_causx_partial_csv(calc_params):
count = calc_params.part_count

columns = ["dataset_id", "variable", "main_subject", "value",
"time","time_precision",
Expand All @@ -314,7 +313,7 @@ def get_causx_partial_csv(calc_params, start=0, end=150):


try:
kg = KnowledgeGraph.generate(cell_mapper, calc_params.sheet, calc_params.wikifier, start, end)
kg = KnowledgeGraph.generate(cell_mapper, calc_params.sheet, calc_params.wikifier, count)
except Exception as e:
raise ValueError(str(e)+"300")

Expand Down
6 changes: 3 additions & 3 deletions backend/causx_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ def get_calc_params(project, data_required=True):
return None

start_end_kwargs = {}
for key in ["data_start", "map_start", "part_start"]:
for key in ["data_start", "map_start"]:#, "part_start"]:
start_end_kwargs[key] = int(request.args.get(key, 0))
for key in ["data_end", "map_end"]:
end = int(request.args.get(key, 0))
if end == 0:
end = None
start_end_kwargs[key] = end
start_end_kwargs["part_end"] = int(request.args.get("part_end", 30))

#start_end_kwargs["part_end"] = int(request.args.get("part_end", 30))
start_end_kwargs["part_count"] = int(request.args.get("part_count", 100))
calc_params = CalcParams(project, data_file, sheet_name, **start_end_kwargs)

calc_params._annotation_path = get_annotation_name(calc_params)
Expand Down
39 changes: 17 additions & 22 deletions backend/t2wml_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_yaml_layers(calc_params):
statement=statementLayer,
cleaned=cleanedLayer,
type=typeLayer)

return layers


Expand Down Expand Up @@ -362,30 +362,25 @@ def update_entities(project, entity_file, updated_entries):


def get_partial_csv(calc_params):
start = calc_params.part_start
end = calc_params.part_end
wikifier = calc_params.wikifier
annotation = calc_params.annotation_path
cell_mapper = PartialAnnotationMapper(calc_params.annotation_path)
kg = KnowledgeGraph.generate(
cell_mapper, calc_params.sheet, wikifier, start, end)
kg = KnowledgeGraph.generate(cell_mapper, calc_params.sheet, wikifier, count=calc_params.part_count)
if not kg.statements:
if cell_mapper.annotation.subject_annotations:
df = pd.DataFrame([], columns=["subject", "property", "value"])
subject_cells = []
(x1, y1), (x2,
y2) = subject_block_cells = cell_mapper.annotation.subject_annotations[0].cell_args
for row in range(y1, y2+1):
for col in range(x1, x2+1):
subject_cells.append(calc_params.sheet[row, col])
df.subject = subject_cells

else:
columns, dict_values = get_cells_and_columns(
kg.statements, calc_params.project)
df = pd.DataFrame.from_dict(dict_values)
df.replace(to_replace=[None], value="", inplace=True)
df = df[columns] # sort the columns
raise ValueError("No statements")
# if cell_mapper.annotation.subject_annotations:
# df = pd.DataFrame([], columns=["subject", "property", "value"])
# subject_cells = []
# (x1, y1), (x2, y2) = cell_mapper.annotation.subject_annotations.cell_args
# for row in range(y1, y2+1):
# for col in range(x1, x2+1):
# subject_cells.append(calc_params.sheet[row, col])
# df.subject = subject_cells

columns, dict_values = get_cells_and_columns(
kg.statements, calc_params.project)
df = pd.DataFrame.from_dict(dict_values)
df.replace(to_replace=[None], value="", inplace=True)
df = df[columns] # sort the columns
dims = list(df.shape)
cells = json.loads(df.to_json(orient="values"))
cells.insert(0, list(df.columns))
Expand Down
Loading

0 comments on commit fef84a5

Please sign in to comment.