Skip to content

Commit

Permalink
feat: add more thing and parse time string
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoshuBaby committed Mar 5, 2024
1 parent 0b48537 commit 06fbdd4
Showing 1 changed file with 56 additions and 5 deletions.
61 changes: 56 additions & 5 deletions src/yuheng/plugin/stat_metadata_clustering/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse
import os
import sys
import datetime
import zoneinfo

current_dir = os.path.dirname(os.path.realpath(__file__))
src_dir = os.path.join(current_dir, "..", "..", "..")
Expand All @@ -10,6 +12,9 @@
from yuheng.component import Node, Way, Relation


LOCAL_TIMEZONE = "Asia/Shanghai"


def main(**kwargs):
# if run in standalone cli, only support input a xml file and then parse it to Carto
# if run by import, both parse xml or pass Carto object is acceptable.
Expand All @@ -36,15 +41,61 @@ def main(**kwargs):
pass

# reverse
metadata_frame = []
metadata_frame_raw = []
for id, element in world.node_dict.items():
metadata_frame.append(("n" + str(element.id), element.timestamp))
metadata_frame_raw.append(
(
"n" + str(element.id),
element.timestamp,
element.uid,
element.changeset,
)
)
for id, element in world.way_dict.items():
metadata_frame.append(("w" + str(element.id), element.timestamp))
metadata_frame_raw.append(
(
"w" + str(element.id),
element.timestamp,
element.uid,
element.changeset,
)
)
for id, element in world.relation_dict.items():
metadata_frame.append(("r" + str(element.id), element.timestamp))
metadata_frame_raw.append(
(
"r" + str(element.id),
element.timestamp,
element.uid,
element.changeset,
)
)
logger.debug(metadata_frame_raw[0])
logger.debug(len(metadata_frame_raw))
metadata_frame = [] # 因为暂时不引入pandas所以用字典做行,用了pandas就直接行数组插入了。
for item in metadata_frame_raw:
timezone_server = datetime.timezone.utc
timezone_user = zoneinfo.ZoneInfo(LOCAL_TIMEZONE)
time_utc_str = item[1]
time_utc = datetime.datetime.strptime(
time_utc_str, "%Y-%m-%dT%H:%M:%SZ"
)
time_utc = time_utc.replace(tzinfo=timezone_server)
time_user = time_utc.astimezone(timezone_user)

metadata_frame.append(
{
"id": item[0],
"uid": item[2],
"changeset": item[3],
"time_year": time_user.year,
"time_month": time_user.month,
"time_day": time_user.day,
"time_hour": time_user.hour,
"time_minute": time_user.minute,
"time_second": time_user.second,
}
)
logger.debug(metadata_frame[0])
logger.debug(len(metadata_frame))


if __name__ == "__main__":
Expand Down

0 comments on commit 06fbdd4

Please sign in to comment.