SankeyExcelParser 1.0.0b0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. SankeyExcelParser/__init__.py +0 -0
  2. SankeyExcelParser/io_excel.py +1867 -0
  3. SankeyExcelParser/io_excel_constants.py +811 -0
  4. SankeyExcelParser/sankey.py +3138 -0
  5. SankeyExcelParser/sankey_utils/__init__.py +0 -0
  6. SankeyExcelParser/sankey_utils/data.py +1118 -0
  7. SankeyExcelParser/sankey_utils/excel_source.py +31 -0
  8. SankeyExcelParser/sankey_utils/flux.py +344 -0
  9. SankeyExcelParser/sankey_utils/functions.py +278 -0
  10. SankeyExcelParser/sankey_utils/node.py +340 -0
  11. SankeyExcelParser/sankey_utils/protos/__init__.py +0 -0
  12. SankeyExcelParser/sankey_utils/protos/flux.py +84 -0
  13. SankeyExcelParser/sankey_utils/protos/node.py +386 -0
  14. SankeyExcelParser/sankey_utils/protos/sankey_object.py +135 -0
  15. SankeyExcelParser/sankey_utils/protos/tag_group.py +95 -0
  16. SankeyExcelParser/sankey_utils/sankey_object.py +165 -0
  17. SankeyExcelParser/sankey_utils/table_object.py +37 -0
  18. SankeyExcelParser/sankey_utils/tag.py +95 -0
  19. SankeyExcelParser/sankey_utils/tag_group.py +206 -0
  20. SankeyExcelParser/su_trace.py +239 -0
  21. SankeyExcelParser/tests/integration/__init__.py +0 -0
  22. SankeyExcelParser/tests/integration/test_base.py +356 -0
  23. SankeyExcelParser/tests/integration/test_run_check_input.py +100 -0
  24. SankeyExcelParser/tests/integration/test_run_conversions.py +96 -0
  25. SankeyExcelParser/tests/integration/test_run_load_input.py +94 -0
  26. SankeyExcelParser/tests/unit/__init__.py +0 -0
  27. SankeyExcelParser-1.0.0b0.data/scripts/run_parse_and_write_excel.py +155 -0
  28. SankeyExcelParser-1.0.0b0.data/scripts/run_parse_excel.py +115 -0
  29. SankeyExcelParser-1.0.0b0.dist-info/METADATA +113 -0
  30. SankeyExcelParser-1.0.0b0.dist-info/RECORD +32 -0
  31. SankeyExcelParser-1.0.0b0.dist-info/WHEEL +5 -0
  32. SankeyExcelParser-1.0.0b0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,165 @@
1
+ """
2
+ Author : Vincent LE DOZE
3
+ Date : 31/05/23
4
+
5
+ This file contains descriptions for sankey proto class
6
+
7
+ """
8
+
9
+
10
+ # Local modules -----------------------------------------------------
11
+ from SankeyExcelParser.sankey_utils.protos.sankey_object import _ProtoSankeyObject
12
+ from SankeyExcelParser.sankey_utils.tag_group import TagGroup
13
+ from SankeyExcelParser.sankey_utils.tag import Tag
14
+ from SankeyExcelParser.sankey_utils.functions import _stdStr
15
+
16
+
17
+ # CLASS ----------------------------------------------------------------------------
18
+ class SankeyObject(_ProtoSankeyObject):
19
+ """
20
+ Define a generic sankey object.
21
+ Inherits from _ProtoSankeyObject but add methods to deal with Tag and TagGroup
22
+ """
23
+
24
+ def __init__(self):
25
+ # Initialize from proto
26
+ _ProtoSankeyObject.__init__(self)
27
+
28
+ @property
29
+ def tags(self):
30
+ return self._tags
31
+
32
+ @tags.setter
33
+ def tags(self, _):
34
+ if type(_) is list:
35
+ if len(_) > 0:
36
+ self._tags = []
37
+ for item in _:
38
+ if type(item) is Tag:
39
+ self._update_tags(item)
40
+ else:
41
+ self._tags = _
42
+ elif type(_) is Tag:
43
+ self._update_tags(_)
44
+
45
+ def add_tag(self, tag: Tag):
46
+ if type(tag) is Tag:
47
+ if tag not in self._tags:
48
+ self._update_tags(tag)
49
+ return
50
+
51
+ def get_taggroups_from_tagtype(self, tagtype):
52
+ taggs = []
53
+ for tagg in self._taggs:
54
+ if tagg.type == tagtype:
55
+ taggs.append(tagg)
56
+ return taggs
57
+
58
+ def get_tags_from_taggroup(
59
+ self,
60
+ tagg,
61
+ return_names_instead_of_refs=False
62
+ ):
63
+ """
64
+ Return the list of tags from given tag group and that are related
65
+ to this object.
66
+
67
+ Parameters
68
+ ----------
69
+ :param tagg: Tagg group from which the tags must belong to.
70
+ :type tagg: TagGroup
71
+
72
+ :param return_names_instead_of_refs: Return a list of tags names.
73
+ :type return_names_instead_of_refs: bool (default=False)
74
+
75
+ Returns
76
+ -------
77
+ :return: List of the tags or None
78
+ :rtype: list[Tag] | list[str] | None
79
+ """
80
+ tags = []
81
+ if type(tagg) is TagGroup:
82
+ for tag in self._tags:
83
+ if tag.group == tagg:
84
+ if return_names_instead_of_refs:
85
+ tags.append(tag.name_unformatted)
86
+ else:
87
+ tags.append(tag)
88
+ if type(tagg) is str:
89
+ tagg = _stdStr(tagg)
90
+ for tag in self._tags:
91
+ if tag.group.name == tagg:
92
+ if return_names_instead_of_refs:
93
+ tags.append(tag.name_unformatted)
94
+ else:
95
+ tags.append(tag)
96
+ if len(tags) == 0:
97
+ tags = None
98
+ return tags
99
+
100
+ def get_tags_from_taggroups(
101
+ self,
102
+ taggs,
103
+ return_names_instead_of_refs=False
104
+ ):
105
+ """
106
+ Return the list of tags from given list of tag groups and
107
+ that are related to this object.
108
+
109
+ Parameters
110
+ ----------
111
+ :param taggs: List of tagg group from which the tags must belong to.
112
+ :type taggs: list[TagGroup]
113
+
114
+ :param return_names_instead_of_refs: Return a list of tags names.
115
+ :type return_names_instead_of_refs: bool (default=False)
116
+
117
+ Returns
118
+ -------
119
+ :return: List of the tags as [or None
120
+ :rtype: list[Tag] | None
121
+ """
122
+ output = []
123
+ if type(taggs) is list:
124
+ for tagg in taggs:
125
+ try:
126
+ tags = self.get_tags_from_taggroup(tagg)
127
+ if tags is not None:
128
+ if return_names_instead_of_refs:
129
+ output.append(
130
+ ':'.join([tag.name_unformatted for tag in tags]))
131
+ else:
132
+ output.append(tags)
133
+ else:
134
+ output.append(None)
135
+ except AttributeError:
136
+ output.append(None)
137
+ return output
138
+
139
+ def has_specific_tag(self, tagg, tag):
140
+ # Find list of tags related to tag group and applied to self
141
+ tags = self.get_tags_from_taggroup(tagg)
142
+ # If no tag found
143
+ if tags is None:
144
+ return False
145
+ # Some tags where found
146
+ if type(tag) is Tag:
147
+ return (tag in tags)
148
+ if type(tag) is str:
149
+ for _ in tags:
150
+ if _.name_unformatted == tag:
151
+ return True
152
+ return False
153
+ # Default answer
154
+ return False
155
+
156
+ def _update_tags(self, _):
157
+ if type(_) is Tag:
158
+ self._tags.append(_)
159
+ self._update_taggs(_)
160
+ _.add_reference(self)
161
+
162
+ def _update_taggs(self, _):
163
+ if type(_) is Tag:
164
+ if _.group not in self._taggs:
165
+ self._taggs.append(_.group)
@@ -0,0 +1,37 @@
1
+ """
2
+ Author : Vincent LE DOZE
3
+ Date : 31/05/23
4
+
5
+ This file contains descriptions for sankey proto class
6
+
7
+ """
8
+
9
+
10
+ # CLASS ----------------------------------------------------------------------------
11
+ class TableObject(object):
12
+ """
13
+ Define an object that is created from given table
14
+
15
+ :param extra_infos: Extra infos related to the object.
16
+ :type extra_infos: dict {info_name: info_content}
17
+
18
+ :param excel_source: Source Excel data.
19
+ :type excel_source: ExcelSource
20
+ """
21
+ def __init__(self):
22
+ self._extra_infos = {}
23
+ self._excel_source = None
24
+
25
+ @property
26
+ def extra_infos(self):
27
+ return self._extra_infos
28
+
29
+ @property
30
+ def extra_infos_name(self):
31
+ return list(self._extra_infos.keys())
32
+
33
+ def add_extra_info(self, info_name, info_content):
34
+ self._extra_infos[info_name] = info_content
35
+
36
+ def add_extra_infos(self, info_dict):
37
+ self._extra_infos.update(info_dict)
@@ -0,0 +1,95 @@
1
+ """
2
+ Author : Vincent LE DOZE
3
+ Date : 31/05/23
4
+
5
+ This file contains descriptions for Tag class
6
+
7
+ """
8
+
9
+
10
+ # Local modules -----------------------------------------------------
11
+ from SankeyExcelParser.sankey_utils.tag_group import _ProtoTagGroup
12
+ from SankeyExcelParser.sankey_utils.sankey_object import _ProtoSankeyObject
13
+ from SankeyExcelParser.sankey_utils.functions import _stdStr, _convertColorToHex
14
+
15
+
16
+ # CLASS ----------------------------------------------------------------------------
17
+ class Tag(object):
18
+ """
19
+ Define any Tag.
20
+
21
+ Parameters
22
+ ----------
23
+ :param name: name of the Tag
24
+ :type name: str
25
+
26
+ :param group: Reference to the tag group from which the tag belongs to.
27
+ :type group: _ProtoTagGroup
28
+
29
+ :param references: Sankey object linked to the tag.
30
+ :type references: list [SankeyObject, ...]
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ name: str,
36
+ group: _ProtoTagGroup
37
+ ):
38
+ # Default values
39
+ self._name = _stdStr(name)
40
+ self._name_unformatted = name.strip().replace('.0', '')
41
+ self._color = ''
42
+ self._group = group
43
+ self._references = []
44
+
45
+ @property
46
+ def name(self):
47
+ return self._name
48
+
49
+ @property
50
+ def name_unformatted(self):
51
+ return self._name_unformatted
52
+
53
+ @property
54
+ def color(self):
55
+ return self._color
56
+
57
+ @property
58
+ def color_in_hex(self):
59
+ return _convertColorToHex(self._color)
60
+
61
+ @color.setter
62
+ def color(self, _):
63
+ if type(_) is str:
64
+ self._color = _
65
+
66
+ @property
67
+ def group(self):
68
+ return self._group
69
+
70
+ @group.setter
71
+ def group(self, _):
72
+ if isinstance(_, _ProtoTagGroup):
73
+ self._group = _
74
+
75
+ @property
76
+ def references(self):
77
+ return self._references.copy()
78
+
79
+ def add_reference(
80
+ self,
81
+ ref: _ProtoSankeyObject
82
+ ):
83
+ self._references.append(ref)
84
+
85
+ def __repr__(self):
86
+ """
87
+ Gives a string representation of Tag object.
88
+
89
+ Returns
90
+ -------
91
+ :return: String format of self.
92
+ :rtype: str
93
+ """
94
+ s = '{}'.format(self.name_unformatted)
95
+ return s
@@ -0,0 +1,206 @@
1
+ """
2
+ Author : Vincent LE DOZE
3
+ Date : 31/05/23
4
+
5
+ This file contains descriptions for Tag class
6
+
7
+ """
8
+
9
+ # Local modules -----------------------------------------------------
10
+ from SankeyExcelParser.sankey_utils.protos.tag_group import _ProtoTagGroup
11
+ from SankeyExcelParser.sankey_utils.tag import Tag
12
+ from SankeyExcelParser.sankey_utils.functions import _stdStr
13
+
14
+ # CONSTANTS -----------------------------------------------------------------------
15
+ ANTI_TAGS_NAME = '0'
16
+
17
+
18
+ # CLASS ----------------------------------------------------------------------------
19
+ class TagGroup(_ProtoTagGroup):
20
+ """
21
+ Define a Tag Group object.
22
+ Inherits from _ProtoTagGroup but adds methods to deal with Tags.
23
+ """
24
+
25
+ def __init__(
26
+ self,
27
+ name: str,
28
+ taggtype: str,
29
+ **kwargs
30
+ ):
31
+ # Init parent class
32
+ _ProtoTagGroup.__init__(self, name, taggtype)
33
+ # Update values
34
+ self.update(**kwargs)
35
+
36
+ def update(
37
+ self,
38
+ **kwargs
39
+ ):
40
+ for key, value in kwargs.items():
41
+ setattr(self, key, value)
42
+
43
+ @property
44
+ def tags(self):
45
+ return self._tags
46
+
47
+ @tags.setter
48
+ def tags(self, _):
49
+ # Input as str
50
+ if type(_) is str:
51
+ if len(_) > 0:
52
+ self._tags = {}
53
+ names_tags = _.split(':')
54
+ for name_tag in names_tags:
55
+ self._tags[_stdStr(name_tag)] = Tag(name_tag, self)
56
+ return
57
+ # Input as list of Tags
58
+ if type(_) is list:
59
+ self._tags = {}
60
+ for tag in _:
61
+ if type(tag) is Tag:
62
+ self._tags[_stdStr(tag.name)] = tag
63
+
64
+ @property
65
+ def anti_tags(self):
66
+ return self._anti_tags
67
+
68
+ def get_or_create_tag(self, tag):
69
+ # Case tag already a Tag
70
+ if type(tag) is Tag:
71
+ # Check if ref name in dict of tags
72
+ ref_tag = _stdStr(tag.name)
73
+ if (ref_tag not in self._tags.keys()) and \
74
+ (ref_tag != self._anti_tags):
75
+ self.add_tag(tag)
76
+ # Return already existing or newly created tag
77
+ return tag
78
+ # Case tag is a name
79
+ if type(tag) is str:
80
+ # Check if ref name in dict of tags
81
+ ref_tag = _stdStr(tag)
82
+ if (ref_tag not in self._tags.keys()) or \
83
+ ((ref_tag == ANTI_TAGS_NAME) and (self._anti_tags is None)):
84
+ self.add_tag(tag)
85
+ # Return already existing or newly created tag
86
+ return self.get_tag_from_name(tag)
87
+ return None
88
+
89
+ def add_tag(self, tag):
90
+ # Case tag already a Tag
91
+ if type(tag) is Tag:
92
+ ref_tag = _stdStr(tag.name)
93
+ tag.group = self
94
+ if ref_tag == ANTI_TAGS_NAME:
95
+ self._anti_tags = tag
96
+ else:
97
+ self._tags[ref_tag] = tag
98
+ return
99
+ # Case tag is a name
100
+ if type(tag) is str:
101
+ ref_tag = _stdStr(tag)
102
+ if ref_tag == ANTI_TAGS_NAME:
103
+ self._anti_tags = Tag(ANTI_TAGS_NAME, self)
104
+ else:
105
+ self._tags[ref_tag] = Tag(tag, self)
106
+ return
107
+
108
+ def get_tag_from_name(
109
+ self,
110
+ tag_name: str,
111
+ include_anti_tags: bool = True
112
+ ):
113
+ ref_tag_name = _stdStr(tag_name) # all the keys are standardized
114
+ if ref_tag_name in self._tags.keys():
115
+ return self._tags[ref_tag_name]
116
+ # Special case : anti tag -> we create it if it does not exist
117
+ if include_anti_tags and (ref_tag_name == ANTI_TAGS_NAME):
118
+ if self._anti_tags is None:
119
+ self._anti_tags = Tag(ANTI_TAGS_NAME, self)
120
+ return self._anti_tags
121
+ return None
122
+
123
+ def get_previous_tag(self, _):
124
+ prev_tag = None
125
+ if type(_) is str:
126
+ for tag_name in self.tags.keys():
127
+ if tag_name == _:
128
+ return prev_tag
129
+ prev_tag = self.tags[tag_name]
130
+ if type(_) is Tag:
131
+ for tag in self.tags.values():
132
+ if tag == _:
133
+ return prev_tag
134
+ prev_tag = tag
135
+ return prev_tag
136
+
137
+ @property
138
+ def tags_str(self):
139
+ return ":".join([tag.name_unformatted for tag in self._tags.values()])
140
+
141
+ @property
142
+ def antagonists_taggs(self):
143
+ return self._antagonists_taggs
144
+
145
+ def add_antagonist_tagg(self, tagg):
146
+ if type(tagg) is TagGroup:
147
+ if tagg not in self._antagonists_taggs:
148
+ self._antagonists_taggs.append(tagg)
149
+ tagg.add_antagonist_tagg(self)
150
+
151
+ def has_antagonists(self):
152
+ return (len(self._antagonists_taggs) > 0)
153
+
154
+ @property
155
+ def colors(self):
156
+ if self.has_colors_defined():
157
+ return ':'.join([tag.color for tag in self._tags.values()])
158
+ else:
159
+ return ''
160
+
161
+ @colors.setter
162
+ def colors(self, _):
163
+ if type(_) is str:
164
+ if len(_) > 0:
165
+ colors = _.split(':')
166
+ for color, tag in zip(colors, self._tags.values()):
167
+ tag.color = color
168
+ return
169
+
170
+ def has_colors_defined(self):
171
+ for tag in self.tags.values():
172
+ if tag.color != '':
173
+ return True
174
+ return False
175
+
176
+ def get_as_dict(self):
177
+ # Init output
178
+ output = {}
179
+ # Get values
180
+ output['name'] = self.name
181
+ output['tags'] = [_.name for _ in self.tags.values()]
182
+ try:
183
+ output['anti_tags'] = self.anti_tags.name
184
+ except Exception:
185
+ pass
186
+ try:
187
+ output['antagonists_taggs'] = self.antagonists_taggs.name
188
+ except Exception:
189
+ pass
190
+ output['colormap'] = self.colormap
191
+ output['is_palette'] = self.is_palette
192
+ return output
193
+
194
+ def __repr__(self):
195
+ """
196
+ Gives a string representation of Taggroup object.
197
+
198
+ Returns
199
+ -------
200
+ :return: String format of self.
201
+ :rtype: str
202
+ """
203
+ s = '{{{0} | {1}}}'.format(
204
+ self.name_unformatted,
205
+ self.tags_str)
206
+ return s