1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# -*- coding: utf-8 -*-
MAX_BAR_VALUE = 100.0 #maximo valor que puede alcanzar una barra
#necesario para el calculo de probabilidades
class Event:
def __init__(self, picture, name, description, appereance_probability, time_span, condicioned_bars):
self.picture = picture
self.name = name
self.description = description
self.appereance_probability = appereance_probability
self.time_span = time_span
self.condicioned_bars = condicioned_bars
self.condicioned_probability = 0.0 #starts in 0.0
def update_probability(self, bars_value_dic):
"""
Updates event probability
"""
prob = 0.0
for bar_con in self.condicioned_bars:
bar_id = bar_con[0]
threshold = bar_con[2]
max_prob = bar_con[3]
bar_value = bars_value_dic[bar_id]
if bar_con[1] == "direct":
if bar_value > threshold:
prob += max_prob * ((bar_value - threshold) / (MAX_BAR_VALUE - threshold))
elif bar_con[1] == "indirect":
if bar_value < threshold:
prob += max_prob * ((threshold - bar_value) / threshold)
elif bar_con[1] == "constant":
if bar_value < threshold :
prob += max_prob
self.condicioned_probability = prob
return int(prob)
def get_probability(self):
#eventually we just take the conditioned
#probability
return int(self.condicioned_probability)
class PersonalEvent(Event):
def __init__(self, picture, kid_animation_path, name, description, appereance_probability, time_span, kind, condicioned_bars, effect, kid_message, preferred_mood=9, message_time_span=5):
Event.__init__(self, picture, name, description, appereance_probability, time_span, condicioned_bars)
self.time_span = time_span
self.time_left = time_span
self.kid_animation_path = kid_animation_path
# Messages at ballon
self.kid_message = kid_message
self.message_time_span = message_time_span
self.preferred_mood = preferred_mood #set as normal by default
self.picture = picture
self.name = name
self.description = description
self.effect = effect
def perform(self):
if(self.time_left):
if self.effect:
self.effect.activate()
self.time_left -= 1
def reset(self):
self.time_left = self.time_span
class SocialEvent(Event):
def __init__(self, picture, person_path, name, description, appereance_probability, time_span, condicioned_bars, message, effect, message_time_span=5):
Event.__init__(self, picture, name, description, appereance_probability, time_span, condicioned_bars)
self.time_span = time_span
self.time_left = time_span
self.person_path = person_path
self.person_message = message
self.message_time_span = message_time_span
self.picture = picture
self.name = name
self.description = description
self.effect = effect
def perform(self):
if(self.time_left):
if self.effect:
self.effect.activate()
self.time_left -= 1
def reset(self):
self.time_left = self.time_span
|