pycityagent 2.0.0a29__py3-none-any.whl → 2.0.0a31__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.
@@ -409,6 +409,50 @@ class AgentGroup:
409
409
  else:
410
410
  for agent in self.agents:
411
411
  _date_time = datetime.now(timezone.utc)
412
+ try:
413
+ nominal_gdp = await agent.memory.get("nominal_gdp")
414
+ except:
415
+ nominal_gdp = []
416
+ try:
417
+ real_gdp = await agent.memory.get("real_gdp")
418
+ except:
419
+ real_gdp = []
420
+ try:
421
+ unemployment = await agent.memory.get("unemployment")
422
+ except:
423
+ unemployment = []
424
+ try:
425
+ wages = await agent.memory.get("wages")
426
+ except:
427
+ wages = []
428
+ try:
429
+ prices = await agent.memory.get("prices")
430
+ except:
431
+ prices = []
432
+ try:
433
+ inventory = await agent.memory.get("inventory")
434
+ except:
435
+ inventory = 0
436
+ try:
437
+ price = await agent.memory.get("price")
438
+ except:
439
+ price = 0.0
440
+ try:
441
+ interest_rate = await agent.memory.get("interest_rate")
442
+ except:
443
+ interest_rate = 0.0
444
+ try:
445
+ bracket_cutoffs = await agent.memory.get("bracket_cutoffs")
446
+ except:
447
+ bracket_cutoffs = []
448
+ try:
449
+ bracket_rates = await agent.memory.get("bracket_rates")
450
+ except:
451
+ bracket_rates = []
452
+ try:
453
+ employees = await agent.memory.get("employees")
454
+ except:
455
+ employees = []
412
456
  _status_dict = {
413
457
  "id": agent._uuid,
414
458
  "day": await self.simulator.get_simulator_day(),
@@ -418,20 +462,17 @@ class AgentGroup:
418
462
  "parent_id": -1,
419
463
  "action": "",
420
464
  "type": await agent.memory.get("type"),
421
- "nominal_gdp": await agent.memory.get("nominal_gdp"),
422
- "real_gdp": await agent.memory.get("real_gdp"),
423
- "unemployment": await agent.memory.get("unemployment"),
424
- "wages": await agent.memory.get("wages"),
425
- "prices": await agent.memory.get("prices"),
426
- "inventory": await agent.memory.get("inventory"),
427
- "price": await agent.memory.get("price"),
428
- "interest_rate": await agent.memory.get("interest_rate"),
429
- "bracket_cutoffs": await agent.memory.get(
430
- "bracket_cutoffs"
431
- ),
432
- "bracket_rates": await agent.memory.get("bracket_rates"),
433
- "employees": await agent.memory.get("employees"),
434
- "customers": await agent.memory.get("customers"),
465
+ "nominal_gdp": nominal_gdp,
466
+ "real_gdp": real_gdp,
467
+ "unemployment": unemployment,
468
+ "wages": wages,
469
+ "prices": prices,
470
+ "inventory": inventory,
471
+ "price": price,
472
+ "interest_rate": interest_rate,
473
+ "bracket_cutoffs": bracket_cutoffs,
474
+ "bracket_rates": bracket_rates,
475
+ "employees": employees,
435
476
  "created_at": _date_time,
436
477
  }
437
478
  _statuses_time_list.append((_status_dict, _date_time))
@@ -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
- table_name = f"socialcity_{exp_id.replace('-', '_')}_{table_type}"
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
- # delete table
25
- cur.execute(f"DROP TABLE IF EXISTS {table_name}") # type:ignore
26
- conn.commit()
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))
@@ -106,10 +110,11 @@ class PgWriter:
106
110
  ]
107
111
  await copy.write_row(_row)
108
112
 
113
+ # @lock_decorator
109
114
  async def async_update_exp_info(self, exp_info: dict[str, Any]):
110
115
  # timestamp不做类型转换
111
116
  TO_UPDATE_EXP_INFO_KEYS_AND_TYPES = [
112
- ("id", str),
117
+ ("id", None),
113
118
  ("name", str),
114
119
  ("num_day", int),
115
120
  ("status", int),
@@ -120,37 +125,31 @@ class PgWriter:
120
125
  ("created_at", None),
121
126
  ("updated_at", None),
122
127
  ]
123
- table_name = f"socialcity_{self.exp_id.replace('-', '_')}_experiment"
128
+ table_name = f"socialcity_experiment"
124
129
  async with await psycopg.AsyncConnection.connect(self._dsn) as aconn:
125
- async with aconn.cursor(row_factory=dict_row) as cur:
126
- await cur.execute(
127
- "SELECT * FROM {table_name}".format(table_name=table_name) # type:ignore
128
- )
129
- record_exists = await cur.fetchall()
130
-
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)
131
134
  if record_exists:
132
135
  # UPDATE
133
136
  columns = ", ".join(
134
137
  f"{key} = %s" for key, _ in TO_UPDATE_EXP_INFO_KEYS_AND_TYPES
135
138
  )
136
139
  update_sql = psycopg.sql.SQL(
137
- f"UPDATE {{}} SET {columns}" # type:ignore
140
+ f"UPDATE {{}} SET {columns} WHERE id='{self.exp_id}'" # type:ignore
138
141
  ).format(psycopg.sql.Identifier(table_name))
139
142
  params = [
140
143
  _type(exp_info[key]) if _type is not None else exp_info[key]
141
144
  for key, _type in TO_UPDATE_EXP_INFO_KEYS_AND_TYPES
142
- ] # + [self.exp_id]
145
+ ]# + [self.exp_id]
143
146
  await cur.execute(update_sql, params)
144
147
  else:
145
148
  # INSERT
146
- keys = ", ".join(
147
- key for key, _ in TO_UPDATE_EXP_INFO_KEYS_AND_TYPES
148
- )
149
- placeholders = ", ".join(
150
- ["%s"] * len(TO_UPDATE_EXP_INFO_KEYS_AND_TYPES)
151
- )
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))
152
151
  insert_sql = psycopg.sql.SQL(
153
- f"INSERT INTO {{}} ({keys}) VALUES ({placeholders})" # type:ignore
152
+ f"INSERT INTO {{}} ({keys}) VALUES ({placeholders})" # type:ignore
154
153
  ).format(psycopg.sql.Identifier(table_name))
155
154
  params = [
156
155
  _type(exp_info[key]) if _type is not None else exp_info[key]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycityagent
3
- Version: 2.0.0a29
3
+ Version: 2.0.0a31
4
4
  Summary: LLM-based城市环境agent构建库
5
5
  License: MIT
6
6
  Author: Yuwei Yan
@@ -50,9 +50,9 @@ pycityagent/metrics/__init__.py,sha256=X08PaBbGVAd7_PRGLREXWxaqm7nS82WBQpD1zvQzc
50
50
  pycityagent/metrics/mlflow_client.py,sha256=g_tHxWkWTDijtbGL74-HmiYzWVKb1y8-w12QrY9jL30,4449
51
51
  pycityagent/metrics/utils/const.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
52
  pycityagent/simulation/__init__.py,sha256=P5czbcg2d8S0nbbnsQXFIhwzO4CennAhZM8OmKvAeYw,194
53
- pycityagent/simulation/agentgroup.py,sha256=0uMoRBektdK9WEXmqYT2gASg42CtS6JjaQ7slP8IWkY,22011
53
+ pycityagent/simulation/agentgroup.py,sha256=dyUnl76ZlO9ZDwCVtg6hB98dkXSurUsD0ADJyGIlP_I,23587
54
54
  pycityagent/simulation/simulation.py,sha256=9kkdgXSEOAN8wiewVFyORksti4IdVNU0opObV6ZYa9k,23344
55
- pycityagent/simulation/storage/pg.py,sha256=xJBR0ROCZpGs6d8ZDtV4iW0awatDvTDPnn6iMozDJfA,7083
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.0a29.dist-info/METADATA,sha256=8zdE1yf3zCJPa0d_M5CYPXULA1fG8dkeveA5EmexLJ0,8033
74
- pycityagent-2.0.0a29.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
75
- pycityagent-2.0.0a29.dist-info/RECORD,,
73
+ pycityagent-2.0.0a31.dist-info/METADATA,sha256=T-AOPv84-eFtT35uA3WvqIpCkQGoCuxR-Tl_zfSqefI,8033
74
+ pycityagent-2.0.0a31.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
75
+ pycityagent-2.0.0a31.dist-info/RECORD,,