Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
greenape committed Apr 18, 2019
1 parent 3cb74a1 commit b0b0267
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
14 changes: 9 additions & 5 deletions flowmachine/flowmachine/core/join_to_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,20 @@ def _get_site_query(self, *, size, polygon_table, geom_col):
def column_names(self) -> List[str]:
right_columns = get_columns_for_level(self.level, self.column_name)
left_columns = self.left.column_names
if "location_id" in right_columns and "location_id" in left_columns:
left_columns.remove("location_id")
for column in right_columns:
if column in left_columns:
left_columns.remove(column)
return left_columns + right_columns

def _make_query(self):

right_columns = get_columns_for_level(self.level, self.column_name)
right_columns = self.right_query.column_names
left_columns = self.left.column_names
if "location_id" in right_columns and "location_id" in left_columns:
left_columns.remove("location_id")
print(right_columns)
print(left_columns)
for column in right_columns:
if column in left_columns:
left_columns.remove(column)

right_columns_str = ", ".join([f"sites.{c}" for c in right_columns])
left_columns_str = ", ".join([f"l.{c}" for c in left_columns])
Expand Down
32 changes: 15 additions & 17 deletions flowmachine/flowmachine/features/network/total_network_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,22 @@ def column_names(self) -> List[str]:
]

def _make_query(self):
cols = ",".join(get_columns_for_level(self.network_object))
group_cols = ",".join(
get_columns_for_level(self.level, self.joined.column_name)
)
sql = """
SELECT {group_cols}, COUNT(*) as total,
cols = get_columns_for_level(self.network_object)
group_cols = get_columns_for_level(self.level, self.joined.column_name)
for column in group_cols:
if column in cols:
cols.remove(column)
cols_str = ",".join(cols)
group_cols_str = ",".join(group_cols)
sql = f"""
SELECT {group_cols_str}, COUNT(*) as total,
datetime FROM
(SELECT DISTINCT {group_cols}, {cols}, datetime FROM
(SELECT {group_cols}, {cols}, date_trunc('{total_by}', x.datetime) AS datetime
FROM ({etu}) x) y) _
GROUP BY {group_cols}, datetime
ORDER BY {group_cols}, datetime
""".format(
total_by=self.total_by,
etu=self.joined.get_query(),
cols=cols,
group_cols=group_cols,
)
(SELECT DISTINCT {group_cols_str}, {cols_str}, datetime FROM
(SELECT {group_cols_str}, {cols_str}, date_trunc('{self.total_by}', x.datetime) AS datetime
FROM ({self.joined.get_query()}) x) y) _
GROUP BY {group_cols_str}, datetime
ORDER BY {group_cols_str}, datetime
"""

return sql

Expand Down

0 comments on commit b0b0267

Please sign in to comment.