1
+ # 50 - Planificador de objetivos de Año Nuevo
2
+ import os
3
+ from enum import Enum
4
+
5
+ class Month (Enum ):
6
+ ENERO = 1
7
+ FEBRERO = 2
8
+ MARZO = 3
9
+ ABRIL = 4
10
+ MAYO = 5
11
+ JUNIO = 6
12
+ JULIO = 7
13
+ AGOSTO = 8
14
+ SEPTIEMBRE = 9
15
+ OCTUBRE = 10
16
+ NOVIEMBRE = 11
17
+ DICIEMBRE = 12
18
+
19
+ class Goals :
20
+ def __init__ (self ):
21
+ self .goal : str = None
22
+ self .count = 0
23
+ self .unit : str = None
24
+ self .time_frame : int = 0
25
+ self .calculated_goal = {Month (x ).name : "" for x in range (1 ,13 )}
26
+ # {goal} ({.calculated_goal[month]} {.unit}/mes). Total: {.count}
27
+
28
+ def create (self ):
29
+ valid_data = True
30
+ print ("Creador de objetivos: " )
31
+ goal = input ("Meta: " )
32
+ count = input ("Cantidad: " )
33
+ unit = input ("Unidad de medida: " )
34
+ time_frame = input ("Plazo en meses (máximo 12): " )
35
+
36
+ if not count .isdigit () or int (count ) < 0 :
37
+ print ("\n La cantidad debe ser un numero entero mayor que 0" )
38
+ valid_data = False
39
+ if not time_frame .isdigit () or int (time_frame ) < 0 :
40
+ print ("\n El plazo debe ser un numero entero mayor que 0" )
41
+ valid_data = False
42
+ if int (time_frame ) > 12 :
43
+ print ("\n El plazo maximo es de 12 meses" )
44
+ valid_data = False
45
+ if valid_data :
46
+ self .goal = goal
47
+ self .count = int (count )
48
+ self .unit = unit
49
+ self .time_frame = int (time_frame )
50
+ else :
51
+ print ("\n Error: no se pudo crear el objetivo" )
52
+
53
+
54
+ def calculate (self ):
55
+ media = self .count / self .time_frame
56
+ media = round (media ,2 )
57
+ for i in range (1 ,self .time_frame + 1 ):
58
+ self .calculated_goal [Month (i ).name ] = media
59
+
60
+
61
+ class Planner :
62
+ def __init__ (self ):
63
+ self .goals = []
64
+ self .planner_text = {Month (x + 1 ).name :[] for x in range (12 )}
65
+
66
+ def add_goal (self ):
67
+ if len (self .goals ) < 10 :
68
+ goal = Goals ()
69
+ try :
70
+ goal .create ()
71
+ goal .calculate ()
72
+ self .goals .append (goal )
73
+ except Exception as e :
74
+ print (f"\n Error en la creacción de la meta" )
75
+ else :
76
+ print ("\n Error: Solo se puede tener un maximo de 10 objetivos!" )
77
+ return
78
+
79
+ def calculate_planner (self ):
80
+ if not self .goals :
81
+ print ("\n Error: No se ha agregado ningun objetivo." )
82
+ return
83
+
84
+ self .planner_text = {Month (x + 1 ).name :[] for x in range (12 )}
85
+ for goal in self .goals :
86
+ for x in range (1 ,13 ):
87
+ if goal .calculated_goal [Month (x ).name ]:
88
+ text = f"{ goal .goal } ({ goal .calculated_goal [Month (x ).name ]} { goal .unit } /mes). Total: { goal .count } "
89
+ self .planner_text [Month (x ).name ].append (text )
90
+
91
+ def show_planner (self ):
92
+ if not self .goals :
93
+ return
94
+ print ("\n Imprimiendo plan detallado:" )
95
+ for month , texts_list in self .planner_text .items ():
96
+ if not self .planner_text [month ]:
97
+ continue
98
+ print (f"\n { month } :" )
99
+ for index , text in enumerate (texts_list ):
100
+ print (f"[ ] { index + 1 } . { text } " )
101
+
102
+ def save_planner (self ):
103
+ if not self .goals :
104
+ print ("\n Error: No se ha agregado ningun objetivo." )
105
+ return
106
+
107
+ file_path = os .path .join (os .path .dirname (
108
+ os .path .abspath (__file__ )), "plan.txt" )
109
+
110
+ with open (file_path , "w" , encoding = "utf-8" ) as f :
111
+ f .write ("Plan detallado\n " )
112
+ for month , texts_list in self .planner_text .items ():
113
+ if not self .planner_text [month ]:
114
+ continue
115
+ f .write (f"\n { month } :" )
116
+ for index , text in enumerate (texts_list ):
117
+ f .write (f"[ ] { index + 1 } . { text } \n " )
118
+ print (f"\n Documento generado con exito en la ruta { file_path } !" )
119
+
120
+ planner_2025 = Planner ()
121
+
122
+
123
+ def show_menu ():
124
+ print ("\n Planificador de objetivos:" )
125
+ print ("1. Añadir objetivo" )
126
+ print ("2. Calcular plan detallado" )
127
+ print ("3. Guardar la planificación" )
128
+ print ("4. Salir" )
129
+
130
+ while True :
131
+
132
+ show_menu ()
133
+
134
+ option = input ("Elige una opción: " )
135
+
136
+ match option :
137
+ case "1" :
138
+ planner_2025 .add_goal ()
139
+ case "2" :
140
+ planner_2025 .calculate_planner ()
141
+ planner_2025 .show_planner ()
142
+ case "3" :
143
+ planner_2025 .calculate_planner ()
144
+ planner_2025 .save_planner ()
145
+ case "4" :
146
+ print ("Saliendo del planificador..." )
147
+ break
148
+ case _:
149
+ print ("Valor invalido." )
0 commit comments