-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpartners.R
90 lines (82 loc) · 3.37 KB
/
partners.R
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
# --------------------
# Imports
# --------------------
partnersData <- read.csv("data/Partners-Table 1.csv")
partnersProjects <- read.csv("data/Projects-Table 1.csv")
partnersNodes <- read.csv("data/partners [Nodes].csv")
colnames(partnersNodes)[colnames(partnersNodes)=="label"] <- "project"
partners <- merge(partnersData, partnersNodes, all.x = TRUE)
# --------------------
# Functions
# --------------------
# Prepare list of edges based on the data
get.edges <- function(partners) {
partnerSplit <- split(partners, partners$partner)
partnersEdges = data.frame(Source = integer(), Target = integer(), Label = character())
for (p in names(partnerSplit)) {
projects = partnerSplit[[p]]
var1 = projects[, c('phase', 'id')]
colnames(var1) <- c('phase1', 'id1')
var2 = projects[, c('phase', 'id')]
colnames(var2) <- c('phase2', 'id2')
edges = merge(var1, var2)
edges = edges[which(edges['id1'] != edges['id2']),]
if (nrow(edges) > 0) {
toAdd = edges[, c('id1', 'phase1', 'id2', 'phase2')]
colnames(toAdd) <- c('Source', 'Phase Source', 'Target', 'Phase Target')
toAdd['Label'] = p
partnersEdges = rbind(partnersEdges, toAdd)
}
}
partnersEdges['Type'] = 'Undirected'
partnersEdges
}
# Compute degrees of connectivity
get.connectivity <- function(partnersEdges) {
acceleratorConnectivity = data.frame(Id = integer(), Phase1 = integer(), Phase2 = integer(), Phase3 = integer(), Phase1and2 = integer(), Phase1or2 = integer(), PhaseAll = integer())
acceleratorsEdges = partnersEdges[which(partnersEdges['Phase Source'] == 3),]
connectivitySplit <- split(acceleratorsEdges, acceleratorsEdges$Source)
for (s in names(connectivitySplit)) {
connections = connectivitySplit[[s]]
partnerSplit = split(connections, connections$Label)
phase1and2count = 0
phase1or2count = 0
for (partner in names(partnerSplit)) {
phases = partnerSplit[[partner]]
tp = phases['Phase Target']
if ((sum(tp == 1) > 0) && (sum(tp == 2) > 0)) phase1and2count = phase1and2count+1
if ((sum(tp == 1) > 0) || (sum(tp == 2) > 0)) phase1or2count = phase1or2count+1
}
targetPhase = connections['Phase Target']
new = data.frame(
Id = c(s),
Phase1 = c(sum(targetPhase == 1)),
Phase2 = c(sum(targetPhase == 2)),
Phase3 = c(sum(targetPhase == 3)),
Phase1and2 = c(phase1and2count),
Phase1or2 = c(phase1or2count),
PhaseAll = c(nrow(targetPhase))
)
acceleratorConnectivity = rbind(acceleratorConnectivity, new)
}
acceleratorConnectivity
}
# --------------------
# Computations
# --------------------
partnersEdges = get.edges(partners)
write.csv(partnersEdges, file="output/partnersEdges.csv")
acceleratorConnectivity = get.connectivity(partnersEdges)
colnames(partnersNodes) <- c('Id', 'Accelerator')
acceleratorConnectivity = merge(acceleratorConnectivity, partnersNodes)
write.csv(acceleratorConnectivity, file="output/acceleratorConnectivity.csv")
acceleratorConnectivity = merge(acceleratorConnectivity, partnersProjects)
toAdd = acceleratorConnectivity[c('Help', 'Phase1', 'Phase2', 'Phase3', 'Phase1and2', 'Phase1or2', 'PhaseAll')]
db = merge(db, toAdd, all.x = TRUE)
remove(toAdd)
db$Phase1[is.na(db$Phase1)] <- 0
db$Phase2[is.na(db$Phase2)] <- 0
db$Phase3[is.na(db$Phase3)] <- 0
db$Phase1and2[is.na(db$Phase1and2)] <- 0
db$Phase1or2[is.na(db$Phase1or2)] <- 0
db$PhaseAll[is.na(db$PhaseAll)] <- 0