Coverage for src/scicom/historicalletters/server.py: 0%
26 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-15 13:26 +0200
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-15 13:26 +0200
1import matplotlib.colors as colors
3import mesa
4import mesa_geo as mg
5from mesa.visualization.modules import ChartVisualization
7from scicom.historicalletters.agents import SenderAgent, RegionAgent
8from scicom.historicalletters.model import HistoricalLetters
10model_params = {
11 #"population": 100,
12 "population": mesa.visualization.Slider(
13 "Number of persons",
14 50, 10, 100, 10,
15 description="Choose how many senders to include in the model.",
16 ),
17 "useSocialNetwork": mesa.visualization.Checkbox(
18 "Create initial social network of agents",
19 False
20 ),
21 "useActivation": mesa.visualization.Checkbox(
22 "Use heterogenous activations",
23 False
24 ),
25 "similarityThreshold": mesa.visualization.Slider(
26 "Similarity threshold",
27 0.5, 0.0, 1.0, 0.1,
28 description="Choose how similar two agents topics have to be, to send a letter.",
29 ),
30 "moveRange": mesa.visualization.Slider(
31 "Range for moving position</br>(% of mean agent distances)",
32 0.1, 0.05, 0.75, 0.05,
33 description="Choose the visibility range for finding potential locations to move to.",
34 ),
35 "letterRange": mesa.visualization.Slider(
36 "Range for letter sending</br>(% of mean agent distances)",
37 0.2, 0.1,1.0, 0.1,
38 description="Choose the visibility range for finding potential recipients.",
39 ),
40}
43def topic_draw(agent):
44 portrayal = {}
45 if isinstance(agent, RegionAgent):
46 try:
47 color = colors.to_hex(agent.has_main_topic())
48 except:
49 print(agent.has_main_topic())
50 raise
51 portrayal["color"] = color
52 elif isinstance(agent, SenderAgent):
53 colortuple = set(agent.topicVec)
54 portrayal["radius"] = 5
55 portrayal["shape"] = "circle"
56 portrayal["color"] = colors.to_hex(colortuple)
57 portrayal["description"] = str(agent.unique_id)
58 return portrayal
61map_element = mg.visualization.MapModule(
62 portrayal_method=topic_draw,
63 view=[52, 12],
64 zoom=4,
65 map_width=700,
66 map_height=500,
67)
69chart = ChartVisualization.ChartModule(
70 [
71 {"Label": "Movements", "Color": "red"},
72 {"Label": "Clusters", "Color": "black"},
73 {'Label': "Letters", "Color": "green"}
74 ],
75 data_collector_name='datacollector',
76)
79server = mesa.visualization.ModularServer(
80 HistoricalLetters,
81 [map_element, chart],
82 "Historical Letters",
83 model_params,
84)