Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point numbers seem to always be recorded as changed #56

Open
simonw opened this issue May 17, 2022 · 3 comments
Open

Floating point numbers seem to always be recorded as changed #56

simonw opened this issue May 17, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented May 17, 2022

In this example:

image

I don't think latitude and longitude should be populated as they have not changed between records (unlike units).

This is from a demo database built against https://github.com/simonw/scrape-san-mateo-fire-dispatch with:

git-history file history.db incidents.json --id id

Relevant code:

# Only record the columns that have changed
if previous_item is not None:
for column in (
item_flattened.keys() | previous_item.keys()
):
if column in RESERVED_SET:
continue
value = item_flattened.get(column)
if value != previous_item.get(column):
updated_values[column] = value
updated_columns.add(column)

@simonw simonw added the bug Something isn't working label May 17, 2022
@simonw
Copy link
Owner Author

simonw commented May 17, 2022

I ran a debugger and it looks like one value is a float and the other is as string:

(Pdb) value
37.6426283504007
(Pdb) previous_item.get(column)
'37.6426283504007'

@simonw
Copy link
Owner Author

simonw commented May 17, 2022

The problem is that previous_item comes from the database:

def get_item(db, item_table, item_id):
previous_items = list(
db.query(
"""
select * from [{item_table}] where _item_id = ?
""".format(
item_table=item_table,
),
[item_id],
)
)
if previous_items:
return previous_items[0]
else:
return None

And the item_table schema for this database is:

CREATE TABLE [item_version] (
   [_id] INTEGER PRIMARY KEY,
   [_item] INTEGER REFERENCES [item]([_id]),
   [_version] INTEGER,
   [_commit] INTEGER REFERENCES [commits]([id]),
   [id] TEXT,
   [date] TEXT,
   [time] TEXT,
   [summary] TEXT,
   [category] TEXT,
   [location] TEXT,
   [latitude] TEXT,
   [longitude] TEXT,
   [units] TEXT,
   [_item_full_hash] TEXT
);

@simonw
Copy link
Owner Author

simonw commented May 17, 2022

This seems to fix it:

diff --git a/git_history/cli.py b/git_history/cli.py
index f3a4c40..b05d345 100644
--- a/git_history/cli.py
+++ b/git_history/cli.py
@@ -349,7 +349,7 @@ def file(
                                     if column in RESERVED_SET:
                                         continue
                                     value = item_flattened.get(column)
-                                    if value != previous_item.get(column):
+                                    if str(value) != str(previous_item.get(column)):
                                         updated_values[column] = value
                                         updated_columns.add(column)
                             else:

Needs a test. More importantly though, I don't understand why this database schema has TEXT for every column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant