pycityagent 2.0.0a28__py3-none-any.whl → 2.0.0a30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,10 @@ from ...utils.pg_query import PGSQL_DICT
|
|
13
13
|
|
14
14
|
def create_pg_tables(exp_id: str, dsn: str):
|
15
15
|
for table_type, exec_strs in PGSQL_DICT.items():
|
16
|
-
|
16
|
+
if not table_type == "experiment":
|
17
|
+
table_name = f"socialcity_{exp_id.replace('-', '_')}_{table_type}"
|
18
|
+
else:
|
19
|
+
table_name = f"socialcity_{table_type}"
|
17
20
|
# # debug str
|
18
21
|
# for _str in [f"DROP TABLE IF EXISTS {table_name}"] + [
|
19
22
|
# _exec_str.format(table_name=table_name) for _exec_str in exec_strs
|
@@ -21,9 +24,10 @@ def create_pg_tables(exp_id: str, dsn: str):
|
|
21
24
|
# print(_str)
|
22
25
|
with psycopg.connect(dsn) as conn:
|
23
26
|
with conn.cursor() as cur:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
if not table_type == "experiment":
|
28
|
+
# delete table
|
29
|
+
cur.execute(f"DROP TABLE IF EXISTS {table_name}") # type:ignore
|
30
|
+
conn.commit()
|
27
31
|
# create table
|
28
32
|
for _exec_str in exec_strs:
|
29
33
|
cur.execute(_exec_str.format(table_name=table_name))
|
@@ -110,7 +114,7 @@ class PgWriter:
|
|
110
114
|
async def async_update_exp_info(self, exp_info: dict[str, Any]):
|
111
115
|
# timestamp不做类型转换
|
112
116
|
TO_UPDATE_EXP_INFO_KEYS_AND_TYPES = [
|
113
|
-
("id",
|
117
|
+
("id", None),
|
114
118
|
("name", str),
|
115
119
|
("num_day", int),
|
116
120
|
("status", int),
|
@@ -121,19 +125,35 @@ class PgWriter:
|
|
121
125
|
("created_at", None),
|
122
126
|
("updated_at", None),
|
123
127
|
]
|
124
|
-
table_name = f"
|
128
|
+
table_name = f"socialcity_experiment"
|
125
129
|
async with await psycopg.AsyncConnection.connect(self._dsn) as aconn:
|
126
|
-
async with aconn.cursor(row_factory=dict_row) as cur:
|
127
|
-
#
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
130
|
+
async with aconn.cursor(row_factory=dict_row) as cur:
|
131
|
+
await cur.execute("SELECT * FROM {table_name} WHERE id=%s".format(table_name = table_name),(self.exp_id,))# type:ignore
|
132
|
+
record_exists = await cur.fetchall()
|
133
|
+
print("record_exists",record_exists)
|
134
|
+
if record_exists:
|
135
|
+
# UPDATE
|
136
|
+
columns = ", ".join(
|
137
|
+
f"{key} = %s" for key, _ in TO_UPDATE_EXP_INFO_KEYS_AND_TYPES
|
138
|
+
)
|
139
|
+
update_sql = psycopg.sql.SQL(
|
140
|
+
f"UPDATE {{}} SET {columns} WHERE id='{self.exp_id}'" # type:ignore
|
141
|
+
).format(psycopg.sql.Identifier(table_name))
|
142
|
+
params = [
|
143
|
+
_type(exp_info[key]) if _type is not None else exp_info[key]
|
144
|
+
for key, _type in TO_UPDATE_EXP_INFO_KEYS_AND_TYPES
|
145
|
+
]# + [self.exp_id]
|
146
|
+
await cur.execute(update_sql, params)
|
147
|
+
else:
|
148
|
+
# INSERT
|
149
|
+
keys = ", ".join(key for key, _ in TO_UPDATE_EXP_INFO_KEYS_AND_TYPES)
|
150
|
+
placeholders = ", ".join(["%s"] * len(TO_UPDATE_EXP_INFO_KEYS_AND_TYPES))
|
151
|
+
insert_sql = psycopg.sql.SQL(
|
152
|
+
f"INSERT INTO {{}} ({keys}) VALUES ({placeholders})" # type:ignore
|
153
|
+
).format(psycopg.sql.Identifier(table_name))
|
154
|
+
params = [
|
155
|
+
_type(exp_info[key]) if _type is not None else exp_info[key]
|
156
|
+
for key, _type in TO_UPDATE_EXP_INFO_KEYS_AND_TYPES
|
157
|
+
]
|
158
|
+
await cur.execute(insert_sql, params)
|
139
159
|
await aconn.commit()
|
@@ -52,7 +52,7 @@ pycityagent/metrics/utils/const.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
|
|
52
52
|
pycityagent/simulation/__init__.py,sha256=P5czbcg2d8S0nbbnsQXFIhwzO4CennAhZM8OmKvAeYw,194
|
53
53
|
pycityagent/simulation/agentgroup.py,sha256=0uMoRBektdK9WEXmqYT2gASg42CtS6JjaQ7slP8IWkY,22011
|
54
54
|
pycityagent/simulation/simulation.py,sha256=9kkdgXSEOAN8wiewVFyORksti4IdVNU0opObV6ZYa9k,23344
|
55
|
-
pycityagent/simulation/storage/pg.py,sha256=
|
55
|
+
pycityagent/simulation/storage/pg.py,sha256=qGrYzJIAzjv8-d3-cle0rY0AN6XB6MgnHkFLBoLmKWU,7251
|
56
56
|
pycityagent/survey/__init__.py,sha256=rxwou8U9KeFSP7rMzXtmtp2fVFZxK4Trzi-psx9LPIs,153
|
57
57
|
pycityagent/survey/manager.py,sha256=S5IkwTdelsdtZETChRcfCEczzwSrry_Fly9MY4s3rbk,1681
|
58
58
|
pycityagent/survey/models.py,sha256=YE50UUt5qJ0O_lIUsSY6XFCGUTkJVNu_L1gAhaCJ2fs,3546
|
@@ -70,6 +70,6 @@ pycityagent/workflow/block.py,sha256=l-z9iJo9_USZQRyj4TLMfihK0-tnNDG0a6jVk9WhG0o
|
|
70
70
|
pycityagent/workflow/prompt.py,sha256=6jI0Rq54JLv3-IXqZLYug62vse10wTI83xvf4ZX42nk,2929
|
71
71
|
pycityagent/workflow/tool.py,sha256=xADxhNgVsjNiMxlhdwn3xGUstFOkLEG8P67ez8VmwSI,8555
|
72
72
|
pycityagent/workflow/trigger.py,sha256=Df-MOBEDWBbM-v0dFLQLXteLsipymT4n8vqexmK2GiQ,5643
|
73
|
-
pycityagent-2.0.
|
74
|
-
pycityagent-2.0.
|
75
|
-
pycityagent-2.0.
|
73
|
+
pycityagent-2.0.0a30.dist-info/METADATA,sha256=-90FMQJqglDQxlQnjqA8r0IA6DbCGA6qS-n78RIwWqE,8033
|
74
|
+
pycityagent-2.0.0a30.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
75
|
+
pycityagent-2.0.0a30.dist-info/RECORD,,
|
File without changes
|