YchKhan commited on
Commit
8cc7d1d
1 Parent(s): 4661d50

Create charts_advanced.py

Browse files
Files changed (1) hide show
  1. charts_advanced.py +343 -0
charts_advanced.py ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import matplotlib.pyplot as plt
3
+ from collections import Counter
4
+ import matplotlib.ticker as ticker
5
+
6
+ def category_chart(file_path):
7
+ plt.close('all')
8
+ # Define expert to specialty mapping
9
+ expert_specialties = {
10
+ "mireille": "Security Trust",
11
+ "khawla": "Network Security",
12
+ "guillaume": "Distributed Networks",
13
+ "vincent": "USIM Management",
14
+ "pierre": "Eco-Design",
15
+ "ly-thanh": "Trend Analysis",
16
+ "nicolas": "Satellite Networks",
17
+ "dorin": "Emergency Communication"
18
+ }
19
+
20
+ # Load the Excel file
21
+ data = pd.read_excel(file_path)
22
+
23
+ # Assuming experts are listed in a column named 'Experts'
24
+ # This part might need to be adjusted based on the actual structure of your Excel file
25
+ experts = data['Expert'].dropna()
26
+
27
+ # Map experts to their specialties
28
+ specialties = experts.apply(lambda expert: expert_specialties.get(expert.strip(), "Other"))
29
+
30
+ # Count occurrences
31
+ specialty_counts = specialties.value_counts()
32
+
33
+ # Convert to DataFrame for plotting
34
+ specialty_counts_df = specialty_counts.reset_index()
35
+ specialty_counts_df.columns = ['Specialty', 'Count']
36
+
37
+ # Plotting
38
+ plt.style.use('dark_background')
39
+ fig, ax = plt.subplots(figsize=(14, 14))
40
+ ax.set_facecolor('#222c52')
41
+ fig.patch.set_facecolor('#222c52')
42
+
43
+ # Alternating colors for the bars
44
+ colors = ['#08F7FE' if i % 2 == 0 else '#FE53BB' for i in range(len(specialty_counts_df))]
45
+ specialty_counts_df.plot(kind='bar', x='Specialty', y='Count', ax=ax, color=colors, edgecolor=colors, alpha=0.5, linewidth=5, legend=None)
46
+
47
+ # Set chart details
48
+ ax.xaxis.label.set_color('white')
49
+ ax.yaxis.label.set_color('white')
50
+ ax.tick_params(axis='x', colors='white', labelsize=12, direction='out', length=6, width=2, rotation=42)
51
+ ax.tick_params(axis='y', colors='white', labelsize=12, direction='out', length=6, width=2)
52
+ ax.set_title('Most Used Expert Specialties', color='white', fontsize=16)
53
+ ax.set_xlabel('Specialty', fontsize=14)
54
+ ax.set_ylabel('Count', fontsize=14)
55
+ ax.grid(True, which='both', axis='y', color='gray', linestyle='-', linewidth=0.5, alpha=0.5)
56
+ ax.set_axisbelow(True)
57
+
58
+ for spine in ax.spines.values():
59
+ spine.set_color('white')
60
+ spine.set_linewidth(2)
61
+ ax.spines['right'].set_visible(False)
62
+ ax.spines['top'].set_visible(False)
63
+
64
+ return fig
65
+
66
+
67
+
68
+
69
+ def status_chart(file_path):
70
+ # Load the Excel file
71
+ plt.close('all')
72
+ data = pd.read_excel(file_path)
73
+
74
+ # Calculate the frequency of each status
75
+ status_counts = data['Status'].value_counts()
76
+
77
+ # Define colors with 50% opacity
78
+ colors = ['#08F7FE80', '#FE53BB80',
79
+ '#fff236de', '#90ff00bf'] # '80' for 50% opacity
80
+
81
+ # Plotting
82
+ fig, ax = plt.subplots()
83
+ fig.patch.set_facecolor('#222c52') # Set the background color of the figure
84
+ ax.set_facecolor('#222c52') # Set the background color of the axes
85
+ wedges, texts, autotexts = ax.pie(status_counts, autopct='%1.1f%%', startangle=90, colors=colors,
86
+ wedgeprops=dict(edgecolor='white', linewidth=1.5))
87
+
88
+ # Set legend
89
+ ax.legend(wedges, status_counts.index, title="Document Status", loc="center left", bbox_to_anchor=(1, 0, 0.5, 1))
90
+
91
+ ax.set_ylabel('') # Remove the y-label
92
+ ax.set_title('Document Status Distribution', color='white')
93
+
94
+ plt.setp(autotexts, size=8, weight="bold", color="white")
95
+
96
+ return fig
97
+
98
+
99
+
100
+ def plot_glowing_line_with_dots_enhanced(ax, x, y, color, label, glow_size=10, base_linewidth=3, markersize=8):
101
+ for i in range(1, glow_size + 1):
102
+ alpha_value = (1.0 / glow_size) * (i / (glow_size / 2))
103
+ if alpha_value > 1.0:
104
+ alpha_value = 1.0
105
+ linewidth = base_linewidth * i * 0.5
106
+ ax.plot(x, y, color=color, linewidth=linewidth, alpha=alpha_value * 0.1)
107
+ ax.plot(x, y, color=color, linewidth=base_linewidth, marker='o', linestyle='-', label=label, markersize=markersize)
108
+
109
+ def company_document_type(file_path, company_names):
110
+ plt.close('all')
111
+ # Convert company_names to a list if it's a string
112
+ if isinstance(company_names, str):
113
+ company_names = [name.strip() for name in company_names.split(',')] # Ensure it's a list even for single company name
114
+
115
+ df = pd.read_excel(file_path)
116
+ plt.style.use('dark_background')
117
+ fig, ax = plt.subplots(figsize=(14, 8))
118
+ ax.set_facecolor('#222c52')
119
+ fig.patch.set_facecolor('#222c52')
120
+
121
+ colors = ['#08F7FE', '#FE53BB', '#fff236'] # Assign more colors for more companies
122
+
123
+ max_count = 0
124
+ for index, company_name in enumerate(company_names):
125
+ df_company = df[df['Source'].str.contains(company_name, case=False, na=False)]
126
+ document_counts = df_company['Type'].value_counts()
127
+ all_document_types = df['Type'].unique()
128
+ document_counts = document_counts.reindex(all_document_types, fill_value=0)
129
+
130
+ x_data = document_counts.index
131
+ y_data = document_counts.values
132
+ ax.fill_between(x_data, y_data, -0.2, color=colors[index % len(colors)], alpha=0.1)
133
+ plot_glowing_line_with_dots_enhanced(ax, x_data, y_data, colors[index % len(colors)], company_name, base_linewidth=4)
134
+
135
+ if max_count < max(y_data):
136
+ max_count = max(y_data)
137
+
138
+ ax.set_xticks(range(len(all_document_types)))
139
+ ax.set_xticklabels(all_document_types, rotation=45, fontsize=12, fontweight='bold')
140
+ ax.yaxis.set_major_locator(ticker.MaxNLocator(integer=True))
141
+ ax.set_ylabel('Count', color='white')
142
+ ax.set_title('Document Types Contributed by Companies')
143
+ ax.grid(True, which='both', axis='both', color='gray', linestyle='-', linewidth=0.5, alpha=0.5)
144
+ ax.set_axisbelow(True)
145
+
146
+ plt.ylim(-0.2, max_count + 1)
147
+
148
+ for spine in ax.spines.values():
149
+ spine.set_color('white')
150
+ spine.set_linewidth(2)
151
+
152
+ ax.spines['right'].set_visible(False)
153
+ ax.spines['top'].set_visible(False)
154
+ ax.spines['left'].set_position(('data', 0))
155
+ plt.legend(facecolor='#222c52', edgecolor='white', fontsize=12)
156
+
157
+ return fig
158
+
159
+
160
+
161
+ def chart_by_expert(file_path, expert_name):
162
+ plt.close('all')
163
+ # Load the Excel file
164
+ data = pd.read_excel(file_path)
165
+
166
+ parts = expert_name.split('/')
167
+
168
+ # The name would be the second part, trim spaces
169
+ name = parts[1].strip()
170
+ # Filter data for the specified expert
171
+ filtered_data = data[data['Expert'] == name.lower()]
172
+
173
+ # Define merge entities mapping
174
+ merge_entities = {
175
+ "Nokia Shanghai Bell": "Nokia",
176
+ "Qualcomm Korea": "Qualcomm",
177
+ "Qualcomm Incorporated": "Qualcomm",
178
+ "Huawei Technologies R&D UK": "Huawei",
179
+ "Hughes Network Systems": "Hughes",
180
+ "HUGHES Network Systems": "Hughes",
181
+ "Hughes Network systems": "Hughes",
182
+ "HUGHES Network Systems Ltd": "Hughes",
183
+ "KT Corp.": "KT Corporation",
184
+ "LG Electronics Inc.": "LG Electronics",
185
+ "LG Uplus": "LG Electronics",
186
+ "OPPO (chongqing) Intelligence": "OPPO",
187
+ "Samsung Electronics GmbH": "Samsung",
188
+ "China Mobile International Ltd": "China Mobile",
189
+ "NOVAMINT": "Novamint",
190
+ "Eutelsat": "Eutelsat Group",
191
+ "Inmarsat Viasat": "Inmarsat",
192
+ "China Telecommunications": "China Telecom",
193
+ "SES S.A.": "SES",
194
+ "Ericsson GmbH": "Ericsson",
195
+ "JSAT": "SKY Perfect JSAT",
196
+ "NEC Europe Ltd": "NEC",
197
+ "Fraunhofer IIS": "Fraunhofer",
198
+ "Hugues Network Systems": "Hughes"
199
+ }
200
+
201
+ # Normalize company names within each cell
202
+ def normalize_companies(company_list, merge_entities):
203
+ normalized = set() # Use a set to avoid duplicates within the same cell
204
+ for company in company_list:
205
+ normalized_name = merge_entities.get(company.strip(), company.strip())
206
+ normalized.add(normalized_name)
207
+ return list(normalized)
208
+
209
+ # Prepare the filtered data
210
+ sources = filtered_data['Source'].dropna()
211
+ split_sources = sources.apply(lambda x: normalize_companies(x.split(', '), merge_entities))
212
+
213
+ # Flatten the list of lists while applying the merge rules
214
+ all_sources = [company for sublist in split_sources for company in sublist]
215
+
216
+ # Count occurrences
217
+ source_counts = Counter(all_sources)
218
+ top_10_sources = source_counts.most_common(10)
219
+
220
+ # Convert to DataFrame for plotting
221
+ top_10_df = pd.DataFrame(top_10_sources, columns=['Company', 'Count'])
222
+
223
+ # Plotting
224
+ plt.style.use('dark_background')
225
+ fig, ax = plt.subplots(figsize=(14, 11))
226
+ ax.set_facecolor('#222c52')
227
+ fig.patch.set_facecolor('#222c52')
228
+
229
+ # Alternating colors for the bars
230
+ colors = ['#08F7FE' if i % 2 == 0 else '#FE53BB' for i in range(len(top_10_df))]
231
+ top_10_df.plot(kind='bar', x='Company', y='Count', ax=ax, color=colors, edgecolor=colors, alpha=0.5, linewidth=5)
232
+
233
+ # Set chart details
234
+ ax.xaxis.label.set_color('white')
235
+ ax.yaxis.label.set_color('white')
236
+ ax.tick_params(axis='x', colors='white', labelsize=12, direction='out', length=6, width=2, rotation=45)
237
+ ax.tick_params(axis='y', colors='white', labelsize=12, direction='out', length=6, width=2)
238
+ ax.set_title(f"Top 10 Cotributors for Expert '{expert_name}'", color='white', fontsize=16)
239
+ ax.set_xlabel('Company', fontsize=14)
240
+ ax.set_ylabel('Count', fontsize=14)
241
+ ax.yaxis.set_major_locator(ticker.MaxNLocator(integer=True))
242
+ ax.grid(True, which='both', axis='y', color='gray', linestyle='-', linewidth=0.5, alpha=0.5)
243
+ ax.set_axisbelow(True)
244
+
245
+ for spine in ax.spines.values():
246
+ spine.set_color('white')
247
+ spine.set_linewidth(2)
248
+ ax.spines['right'].set_visible(False)
249
+ ax.spines['top'].set_visible(False)
250
+
251
+ return fig
252
+
253
+
254
+
255
+ # @title Top 10 des entreprises en termes de publications
256
+
257
+
258
+
259
+ def generate_company_chart(file_path):
260
+ # plt.close('all')
261
+ # Define merge entities mapping
262
+ merge_entities = {
263
+ "Nokia Shanghai Bell": "Nokia",
264
+ "Qualcomm Korea": "Qualcomm",
265
+ "Qualcomm Incorporated": "Qualcomm",
266
+ "Huawei Technologies R&D UK": "Huawei",
267
+ "Hughes Network Systems": "Hughes",
268
+ "HUGHES Network Systems": "Hughes",
269
+ "Hughes Network systems": "Hughes",
270
+ "HUGHES Network Systems Ltd": "Hughes",
271
+ "KT Corp.": "KT Corporation",
272
+ "Deutsche Telekom AG": "Deutsche Telekom",
273
+ "LG Electronics Inc.": "LG Electronics",
274
+ "LG Uplus": "LG Electronics",
275
+ "OPPO (chongqing) Intelligence": "OPPO",
276
+ "Samsung Electronics GmbH": "Samsung",
277
+ "China Mobile International Ltd": "China Mobile",
278
+ "NOVAMINT": "Novamint",
279
+ "Eutelsat": "Eutelsat Group",
280
+ "Inmarsat Viasat": "Inmarsat",
281
+ "China Telecommunications": "China Telecom",
282
+ "SES S.A.": "SES",
283
+ "Ericsson GmbH": "Ericsson",
284
+ "JSAT": "SKY Perfect JSAT",
285
+ "NEC Europe Ltd": "NEC",
286
+ "Fraunhofer IIS": "Fraunhofer",
287
+ "Hugues Network Systems": "Hughes"
288
+ }
289
+
290
+ # Function to normalize company names within each cell
291
+ def normalize_companies(company_list, merge_entities):
292
+ normalized = set() # Use a set to avoid duplicates within the same cell
293
+ for company in company_list:
294
+ normalized_name = merge_entities.get(company.strip(), company.strip())
295
+ normalized.add(normalized_name)
296
+ return list(normalized)
297
+
298
+ # Load the Excel file
299
+ data = pd.read_excel(file_path)
300
+
301
+ # Prepare the data
302
+ sources = data['Source'].dropna()
303
+ split_sources = sources.apply(lambda x: normalize_companies(x.split(', '), merge_entities))
304
+
305
+ # Flatten the list of lists while applying the merge rules
306
+ all_sources = [company for sublist in split_sources for company in sublist]
307
+
308
+ # Count occurrences
309
+ source_counts = Counter(all_sources)
310
+ top_10_sources = source_counts.most_common(10)
311
+
312
+ # Convert to DataFrame for plotting
313
+ top_10_df = pd.DataFrame(top_10_sources, columns=['Company', 'Count'])
314
+
315
+ # Plotting
316
+ plt.style.use('dark_background')
317
+ fig, ax = plt.subplots(figsize=(14, 12))
318
+ ax.set_facecolor('#222c52')
319
+ fig.patch.set_facecolor('#222c52')
320
+
321
+ # Alternating colors for the bars
322
+ colors = ['#08F7FE' if i % 2 == 0 else '#FE53BB' for i in range(len(top_10_df))]
323
+ top_10_df.plot(kind='bar', x='Company', y='Count', ax=ax, color=colors, edgecolor=colors, alpha=0.5, linewidth=5, legend=None)
324
+
325
+ # Set chart details
326
+ ax.xaxis.label.set_color('white')
327
+ ax.yaxis.label.set_color('white')
328
+ ax.tick_params(axis='x', colors='white', labelsize=16, direction='out', length=6, width=2, rotation=37)
329
+ ax.tick_params(axis='y', colors='white', labelsize=12, direction='out', length=6, width=2)
330
+ ax.set_title('Top 10 Contributors: Ranking Company Contributions', color='white', fontsize=16)
331
+ ax.set_xlabel('Company', fontsize=14)
332
+ ax.set_ylabel('Count', fontsize=14)
333
+ ax.grid(True, which='both', axis='y', color='gray', linestyle='-', linewidth=0.5, alpha=0.5)
334
+ ax.set_axisbelow(True)
335
+
336
+ for spine in ax.spines.values():
337
+ spine.set_color('white')
338
+ spine.set_linewidth(2)
339
+ ax.spines['right'].set_visible(False)
340
+ ax.spines['top'].set_visible(False)
341
+
342
+ #plt.show()
343
+ return fig