reading fucking cells

This commit is contained in:
2023-01-24 15:15:53 +01:00
parent 89dc8ed54a
commit be83cbd988
31 changed files with 340 additions and 80 deletions

Binary file not shown.

Binary file not shown.

69
econ/cells/cell.py Normal file
View File

@@ -0,0 +1,69 @@
from ..exchange import Exchange
from ..commoditys import commoditys as cm
class Cell:
"""
A cell is the basic procedual structure of this simulation. If a cell contains pop then this Cell will have a local market.
If the cell is contained in a province then the cell will have a
"""
name=None # Unique ID/Name of the cell
loc_x=0
loc_y=0
area=1
pop=0 # Population of the cell
demand_tags=[] # Demands by 1 pop
world_tags=[] # Resources provided by cell each episode
demand={}
world={}
exchange: None
def __init__(self,name,x,y,area,pop,demand,world) -> None:
self.name=name
self.loc_x=x
self.loc_y=y
self.area=area
self.pop=pop*1000
self.demand_tags=demand
self.demand={}
self.world_tags=world
self.world={}
if pop>0:
self.exchange=Exchange()
# build per person demand
for tag in self.demand_tags:
d=cm.demand_tags[tag]
for dem in d:
k=list(dem.keys())[0]
v=dem[k]
if k not in self.demand:
self.demand[k]=v*pop
else:
self.demand[k]+=v*pop
for tag in self.world_tags:
d=cm.world_tags[tag]
for wor in d:
k=list(wor.keys())[0]
v=wor[k]
if k not in self.world:
self.world[k]=v*area
else:
self.world[k]+=v*area
def create_cells_from_world_cells(cells) -> list:
"""
Creates cells based on a list of cells provided from a world
"""
ret_cells=[]
# For now make it very simple
for i in cells:
cell=Cell(i["i"],i["p"][0],i["p"][1],i["area"],i["pop"],["basic"],["grass"])
ret_cells.append(cell)
return ret_cells

10
econ/cells/db.py Normal file
View File

@@ -0,0 +1,10 @@
import json
world = {}
def load_world(filepath):
file= open(filepath, 'r',encoding='UTF-8')
data=file.readlines()
global world
world = json.loads(data[0])
return world