-
-
Notifications
You must be signed in to change notification settings - Fork 435
t.list: Add support for listing multiple dataset types #7731
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
2bf81a0
9380913
91035e8
ac3d6dd
eaf31d5
0957f85
50aef44
35ba70a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,7 @@ def get_dataset_list( | |
| This method returns a dictionary, the keys are the available mapsets, | ||
| the values are the rows from the SQL database query. | ||
|
|
||
| :param type: The type of the datasets (strds, str3ds, stvds, raster, | ||
| :param type: A list of dataset types (strds, str3ds, stvds, raster, | ||
| raster_3d, vector) | ||
| :param temporal_type: The temporal type of the datasets (absolute, | ||
| relative) | ||
|
|
@@ -76,15 +76,15 @@ def get_dataset_list( | |
| ... ) | ||
| >>> mapset = tgis.get_current_mapset() | ||
| >>> stds_list = tgis.list_stds.get_dataset_list( | ||
| ... "strds", "absolute", columns="name" | ||
| ... ["strds"], "absolute", columns="name" | ||
| ... ) | ||
| >>> rows = stds_list[mapset] | ||
| >>> for row in rows: | ||
| ... if row["name"] == name: | ||
| ... print(True) | ||
| True | ||
| >>> stds_list = tgis.list_stds.get_dataset_list( | ||
| ... "strds", | ||
| ... ["strds"], | ||
| ... "absolute", | ||
| ... columns="name,mapset", | ||
| ... where="mapset = '%s'" % (mapset), | ||
|
|
@@ -101,31 +101,38 @@ def get_dataset_list( | |
|
|
||
| result = {} | ||
|
|
||
| for mapset in dbif.tgis_mapsets: | ||
| if temporal_type == "absolute": | ||
| table = type + "_view_abs_time" | ||
| else: | ||
| table = type + "_view_rel_time" | ||
|
|
||
| if columns and columns.find("all") == -1: | ||
| sql = "SELECT " + str(columns) + " FROM " + table | ||
| else: | ||
| sql = "SELECT * FROM " + table | ||
|
|
||
| if where: | ||
| sql += " WHERE " + where | ||
| sql += " AND mapset = '%s'" % (mapset) | ||
| else: | ||
| sql += " WHERE mapset = '%s'" % (mapset) | ||
|
|
||
| if order: | ||
| sql += " ORDER BY " + order | ||
| for dtype in type: | ||
| for mapset in dbif.tgis_mapsets: | ||
| if temporal_type == "absolute": | ||
| table = dtype + "_view_abs_time" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the intention is to be able to list all STDS in one go, should we not support also multiple / list input for temporal_type?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree and t.list already allows that, just not the function.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That probably means the temporal_type should always go into the JSON and CSV output too, no?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The temporal_type is already in CSV and JSON with columns=all, it could be added explicitly as one of the options, but I am not sure it's worth it. |
||
| else: | ||
| table = dtype + "_view_rel_time" | ||
|
|
||
| dbif.execute(sql, mapset=mapset) | ||
| rows = dbif.fetchall(mapset=mapset) | ||
| if columns and columns.find("all") == -1: | ||
| sql = "SELECT " + columns + " FROM " + table | ||
| else: | ||
| sql = "SELECT * FROM " + table | ||
|
|
||
| if rows: | ||
| result[mapset] = rows | ||
| if where: | ||
| sql += " WHERE " + where | ||
| sql += " AND mapset = '%s'" % (mapset) | ||
| else: | ||
| sql += " WHERE mapset = '%s'" % (mapset) | ||
|
|
||
| if order: | ||
| sql += " ORDER BY " + order | ||
|
|
||
| dbif.execute(sql, mapset=mapset) | ||
| rows = dbif.fetchall(mapset=mapset) | ||
|
|
||
| if rows: | ||
| if mapset not in result: | ||
| result[mapset] = [] | ||
| for row in rows: | ||
| row_dict = dict(row) | ||
| if len(type) > 1: | ||
| row_dict["type"] = dtype | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Back to the question if the keys should be consistent, regardless if t.list is run with multiple or single type (or possibly single or multiple temporal_type input? I tend to say: make the dict (JSON) output structure consistent / predictable. But no strong opinion. It should just be deliberate. Also, could this block be solved simpler with a dict-comprehension and/or a dict-update? (consult
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The JSON should not have mixed items (each item in an array should have the same set of keys), which is the case now because we don't mix maps and datasets. In the comment above I was thinking to add the type key always for JSON and CSV. I hope I am not missing anything here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but e.g semantic_label is only available for STRDS. So, should columns that do not exist for every dataset type just be empty? Just me thinking out loud...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I commented on this below, I think we need to select the intersection of the different columns. |
||
| result[mapset].append(row_dict) | ||
|
|
||
| if connection_state_changed: | ||
| dbif.close() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.