Skip to content

Commit

Permalink
fix freq update bugs, so chart works properly after update
Browse files Browse the repository at this point in the history
  • Loading branch information
interrogator committed Aug 23, 2019
1 parent ff0b465 commit 5f1745c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
23 changes: 15 additions & 8 deletions buzzword/parts/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def _new_chart(n_clicks, table_from, chart_type, top_n, transpose, session_table
# get correct dataset to chart

this_table = session_tables[str(table_from)]
this_table = _tuple_or_list(this_table, tuple)
df = FREQUENCY_TABLES[_tuple_or_list(this_table[:6], tuple)]

# transpose and cut down items to plot
Expand Down Expand Up @@ -362,6 +361,10 @@ def _new_table(

specs, corpus = _get_specs_and_corpus(search_from, session_search, CORPORA, slug)

# do not store the df._n in store EVER
if isinstance(specs, (list, tuple)):
specs = specs[:-1]

sort = sort or "total"

relative, keyness = _translate_relative(relkey, CORPORA[slug])
Expand Down Expand Up @@ -390,17 +393,21 @@ def _new_table(
if exists is not False:
exists_as_tuple = _tuple_or_list(exists, tuple)

# if we are updating the table:table_size
# if we are updating the table:
if updating:
# get the whole table from master dict of them
table = FREQUENCY_TABLES[exists_as_tuple[:6]]
exists[-1] += 1
# increment the last number, shows number of edits
exists_as_list = _tuple_or_list(exists, list)
exists_as_list[-1] += 1
# re-store it with the correct number of edits
session_tables[key] = exists_as_list
# fix rows and columns
old_dim = table.shape
table = table[[i["id"] for i in current_cols[1:]]]
table = table.loc[[i["_" + table.index.name] for i in current_data]]
# store again
exists = _tuple_or_list(exists, list)
session_tables[key] = exists
FREQUENCY_TABLES[exists_as_tuple[:6]] = table
# store table again with same key
FREQUENCY_TABLES[_tuple_or_list(exists_as_list[:6], tuple)] = table
elif exists:
msg = "Table already exists. Switching to that one to save memory."
table = FREQUENCY_TABLES[exists_as_tuple[:6]]
Expand Down Expand Up @@ -431,7 +438,7 @@ def _new_table(
relative = None

# then store the search information in store/freq table spaces
session_tables[idx] = _tuple_or_list(this_table[:6], list)
session_tables[idx] = _tuple_or_list(this_table, list)
FREQUENCY_TABLES[_tuple_or_list(this_table[:6], tuple)] = table

if updating:
Expand Down
2 changes: 1 addition & 1 deletion buzzword/parts/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _make_table_name(history):
basic = f"{show} by {subcorpora}{relkey}, sorting by {sort}"
if updates:
basic += f", {updates} edits"
parent = specs[-3] if isinstance(specs, (tuple, list)) else 0
parent = specs[4] if isinstance(specs, (tuple, list)) else 0
if not parent:
return basic
return f"{basic} -- from search #{parent}"
Expand Down
4 changes: 2 additions & 2 deletions corpora.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"desc": "Script of Spike Lee's 1989 drama, with various speaker and scene annotations",
"len": 17713,
"drop_columns": ["voice_over", "camera_angle"],
"disable": false,
"disabled": false,
"date": "1989",
"load": true,
"url": "https://en.wikipedia.org/wiki/Do_the_Right_Thing"
Expand All @@ -16,7 +16,7 @@
"desc": "Text of the Unabomber's manifesto",
"len": 37347,
"add_governor": false,
"disable": false,
"disabled": false,
"date": "1995",
"load": true,
"url": "https://en.wikipedia.org/wiki/Ted_Kaczynski#Industrial_Society_and_Its_Future"
Expand Down

0 comments on commit 5f1745c

Please sign in to comment.