|
14 | 14 | import math
|
15 | 15 | import numpy as np
|
16 | 16 | import calendar
|
| 17 | +import networkx as nx |
17 | 18 |
|
18 | 19 | import logging
|
19 | 20 |
|
@@ -320,7 +321,7 @@ def get_commit_editing_dag(sqlite_db_file, time_from=None, time_to=None, filenam
|
320 | 321 | return dag, node_info, edge_info
|
321 | 322 |
|
322 | 323 |
|
323 |
| -def get_coediting_network(sqlite_db_file, author_identifier='author_id', time_from=None, time_to=None): |
| 324 | +def get_coediting_network(sqlite_db_file, author_identifier='author_id', time_from=None, time_to=None, engine='pathpy'): |
324 | 325 | """
|
325 | 326 | Returns coediting network containing links between authors who coedited at least one line of
|
326 | 327 | code within a given time window.
|
@@ -391,19 +392,41 @@ def get_coediting_network(sqlite_db_file, author_identifier='author_id', time_fr
|
391 | 392 | node_info = {}
|
392 | 393 | edge_info = {}
|
393 | 394 |
|
394 |
| - t = pp.TemporalNetwork() |
395 |
| - for row in data.itertuples(): |
396 |
| - if (row.time >= time_from) and (row.time <= time_to) and not \ |
397 |
| - (row.post_author == row.pre_author): |
398 |
| - if not (pd.isnull(row.post_author) or pd.isnull(row.pre_author)): |
399 |
| - t.add_edge(row.post_author, |
400 |
| - row.pre_author, |
401 |
| - row.time, |
402 |
| - directed=True) |
403 |
| - |
404 |
| - return t, node_info, edge_info |
405 |
| - |
406 |
| - |
| 395 | + if engine=='pathpy': |
| 396 | + t = pp.TemporalNetwork() |
| 397 | + for row in data.itertuples(): |
| 398 | + if (row.time >= time_from) and (row.time <= time_to) and not \ |
| 399 | + (row.post_author == row.pre_author): |
| 400 | + if not (pd.isnull(row.post_author) or pd.isnull(row.pre_author)): |
| 401 | + t.add_edge(row.post_author, |
| 402 | + row.pre_author, |
| 403 | + row.time, |
| 404 | + directed=True) |
| 405 | + |
| 406 | + return t, node_info, edge_info |
| 407 | + elif engine=='networkx': |
| 408 | + n = nx.DiGraph() |
| 409 | + for row in data.itertuples(): |
| 410 | + if (row.time >= time_from) and (row.time <= time_to) and not \ |
| 411 | + (row.post_author == row.pre_author): |
| 412 | + if not (pd.isnull(row.post_author) or pd.isnull(row.pre_author)): |
| 413 | + n.add_node(row.post_author) |
| 414 | + n.add_node(row.pre_author) |
| 415 | + n.add_edge(row.post_author, |
| 416 | + row.pre_author) |
| 417 | + if author_identifier=='author_id': |
| 418 | + edge = (int(row.post_author), int(row.pre_author)) |
| 419 | + else: |
| 420 | + edge = (row.post_author, row.pre_author) |
| 421 | + |
| 422 | + if edge in edge_info: |
| 423 | + edge_info[edge]['times'].append(row.time) |
| 424 | + else: |
| 425 | + edge_info[edge] = {'times': [row.time]} |
| 426 | + return n, node_info, edge_info |
| 427 | + else: |
| 428 | + raise Exception('Not implemented network engine.') |
| 429 | + |
407 | 430 | def get_coauthorship_network(sqlite_db_file, author_identifier='author_id', time_from=None, time_to=None):
|
408 | 431 | """
|
409 | 432 | Returns coauthorship network containing links between authors who coedited at least one code
|
|
0 commit comments