-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename SV column names to SV ids. (#236)
- Loading branch information
Showing
17 changed files
with
433 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
dcid,date,Variable 1,Variable 2 | ||
dcid,date,custom/statvar_3,custom/statvar_4 | ||
geoId/01,2021,555,666 | ||
geoId/122,2022,321,123456 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
dcid,date,var1,var2 | ||
dcid,date,custom/statvar_1,custom/statvar_2 | ||
country/USA,2021,555,666 | ||
country/IND,2022,321,123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
dcid,date,var1,var2 | ||
dcid,date,custom/statvar_1,custom/statvar_2 | ||
s2CellId/0x80982b0000000000,2021,555,666 | ||
s2CellId/0x3be7c90000000000,2022,321,123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
dcid,date,var1,var2 | ||
dcid,date,custom/statvar_1,custom/statvar_2 | ||
country/USA,2021,555,666 | ||
country/IND,2022,321,123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
{ | ||
"status": "SUCCESS", | ||
"startTime": "2023-10-23 10:50:22.644858", | ||
"lastUpdate": "2023-10-23 10:50:30.534262", | ||
"startTime": "2023-10-23 14:43:10.816166", | ||
"lastUpdate": "2023-10-23 14:43:17.797630", | ||
"importFiles": { | ||
"countries.csv": { | ||
"status": "SUCCESS", | ||
"startTime": "2023-10-23 10:50:22.645832", | ||
"lastUpdate": "2023-10-23 10:50:23.689136" | ||
"startTime": "2023-10-23 14:43:10.816848", | ||
"lastUpdate": "2023-10-23 14:43:11.638482" | ||
}, | ||
"geoids.csv": { | ||
"status": "SUCCESS", | ||
"startTime": "2023-10-23 10:50:23.693980", | ||
"lastUpdate": "2023-10-23 10:50:23.697093" | ||
"startTime": "2023-10-23 14:43:11.641372", | ||
"lastUpdate": "2023-10-23 14:43:11.644468" | ||
}, | ||
"latlng.csv": { | ||
"status": "SUCCESS", | ||
"startTime": "2023-10-23 10:50:23.698691", | ||
"lastUpdate": "2023-10-23 10:50:24.975047" | ||
"startTime": "2023-10-23 14:43:11.645726", | ||
"lastUpdate": "2023-10-23 14:43:12.729606" | ||
}, | ||
"powerplants.csv": { | ||
"status": "SUCCESS", | ||
"startTime": "2023-10-23 10:50:24.977544", | ||
"lastUpdate": "2023-10-23 10:50:30.267462" | ||
"startTime": "2023-10-23 14:43:12.732431", | ||
"lastUpdate": "2023-10-23 14:43:17.590325" | ||
}, | ||
"s2cells.csv": { | ||
"status": "SUCCESS", | ||
"startTime": "2023-10-23 10:50:30.268803", | ||
"lastUpdate": "2023-10-23 10:50:30.270341" | ||
"startTime": "2023-10-23 14:43:17.591729", | ||
"lastUpdate": "2023-10-23 14:43:17.593462" | ||
}, | ||
"wikidataids.csv": { | ||
"status": "SUCCESS", | ||
"startTime": "2023-10-23 10:50:30.271283", | ||
"lastUpdate": "2023-10-23 10:50:30.529614" | ||
"startTime": "2023-10-23 14:43:17.594229", | ||
"lastUpdate": "2023-10-23 14:43:17.794165" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright 2023 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from dataclasses import dataclass | ||
import logging | ||
|
||
import pandas as pd | ||
from stats.config import Config | ||
from stats.data import StatVar | ||
from stats.data import StatVarGroup | ||
from stats.data import Triple | ||
from util.filehandler import FileHandler | ||
|
||
_CUSTOM_SV_ID_PREFIX = "custom/statvar_" | ||
_CUSTOM_GROUP_ID_PREFIX = "custom/g/group_" | ||
_ROOT_GROUP_ID = "dc/g/Root" | ||
|
||
|
||
class Nodes: | ||
|
||
def __init__(self, config: Config) -> None: | ||
self.config = config | ||
# Dictionary of SVs from column name to SV | ||
self.variables: dict[str, StatVar] = {} | ||
# Dictionary of SVGs from SVG path to SVG | ||
self.groups: dict[str, StatVarGroup] = {} | ||
|
||
def variable(self, sv_column_name: str) -> StatVar: | ||
if sv_column_name in self.variables: | ||
return self.variables[sv_column_name] | ||
|
||
var_cfg = self.config.variable(sv_column_name) | ||
group = self.group(var_cfg.group_path) | ||
group_id = group.id if group else _ROOT_GROUP_ID | ||
self.variables[sv_column_name] = StatVar( | ||
f"{_CUSTOM_SV_ID_PREFIX}{len(self.variables) + 1}", | ||
var_cfg.name, | ||
description=var_cfg.description, | ||
nl_sentences=var_cfg.nl_sentences, | ||
group_id=group_id, | ||
) | ||
return self.variables[sv_column_name] | ||
|
||
def group(self, group_path: str) -> StatVarGroup | None: | ||
if not group_path: | ||
return None | ||
if group_path in self.groups: | ||
return self.groups[group_path] | ||
|
||
tokens = group_path.split("/") | ||
for index in range(len(tokens)): | ||
path = "/".join(tokens[:index + 1]) | ||
if path not in self.groups: | ||
parent_path = "" if "/" not in path else path[:path.rindex("/")] | ||
parent_id = (self.groups[parent_path].id | ||
if parent_path in self.groups else _ROOT_GROUP_ID) | ||
self.groups[path] = StatVarGroup( | ||
f"{_CUSTOM_GROUP_ID_PREFIX}{len(self.groups) + 1}", tokens[index], | ||
parent_id) | ||
|
||
return self.groups[group_path] | ||
|
||
def triples(self, triples_fh: FileHandler | None = None) -> list[Triple]: | ||
triples: list[Triple] = [] | ||
for group in self.groups.values(): | ||
triples.extend(group.triples()) | ||
for variable in self.variables.values(): | ||
triples.extend(variable.triples()) | ||
|
||
if triples_fh: | ||
logging.info("Writing %s triples to: %s", len(triples), str(triples_fh)) | ||
triples_fh.write_string(pd.DataFrame(triples).to_csv(index=False)) | ||
|
||
return triples |
Oops, something went wrong.