-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDGs.py
148 lines (115 loc) · 2.85 KB
/
SDGs.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 16 11:34:20 2021
It represents the set of SDGs that belongs to the Agenda 2030.
Each SDG has:
- a Goal
- a list of Target
@author: Claudia Lorusso
"""
#total number of SDGs
MAX_SDGs = 17
class SDGs:
"""
It represents the set of SDGs that belongs to the Agenda 2030.
Each SDG has:
- a Goal
- a list of Target
"""
def __init__(self):
self.__sdgs__ = []
self.__max__ = MAX_SDGs
def add(self, sdg):
"""
Adds a SDG to the SDG list.
:parameter:
----------
sdg : SDG to insert into the SDG list
:return:
-------
None.
"""
if self.__sdgs__ == []:
sdg_list = [sdg]
self.__sdgs__ = sdg_list
else:
self.__sdgs__.append(sdg)
self.__sdgs__.sort(key=lambda x: x.get_Goal_id())
def get_SDGs(self):
"""
:return: SDGs
-------
Rreturns a SDGs object containing each SDG
"""
return self.__sdgs__
def get_SDG(self, id):
"""
Returns the id-th SDG.
Parameters
----------
:parameter: id : integer identifier of the SDG to be returned.
:return: SDG
-------
The is-th SDG
"""
if(id >= 1 and id <= MAX_SDGs):
return self.__sdgs__[id - 1]
else:
print("Inserire un id valido.")
def __iter__(self):
"""
re-defines the iterator
"""
self.n = 0
return self
def __next__(self):
"""
re-defines the next's iterator
"""
if (self.n < self.__max__):
result = self.__sdgs__[self.n]
self.n += 1
return result
else:
raise StopIteration
def __str__(self):
"""
Override of str function
:return:
-------
Returns a string containing each SDG that belongs to the Agenda 2030.:
"AGENDA 2030:"
"SDG 1"
...
"SDG 17"
"""
sdgs = "AGENDA 2030:\n"
for sdg in self.__sdgs__:
sdgs = sdgs + str(sdg) + "\n"
return sdgs
def print_SDGs(self):
"""
Prints each SDG
"""
print(self)
def get_len_SDGs(self):
"""
Returns the total number of SDGs
:return:
-------
int
Total number of SDGs
"""
return len(self.__sdgs__)
def get_len_tot_target(self):
"""
returns the number of targets
:return:
-------
tot : int
total number of targets
"""
tot = 0
for sdg in self.__sdgs__:
tot += sdg.get_len_target()
return tot