-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.R
More file actions
160 lines (133 loc) · 5.63 KB
/
Copy pathutils.R
File metadata and controls
160 lines (133 loc) · 5.63 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
applyRules <- function(data, rules) {
for (i in 1:nrow(rules)) {
row <- rules[i,]
if (nrow(data[data$MIME==row$MIME1 & data$VERSION==row$VERSION1 & !is.na(data$VERSION) & !is.na(data$MIME),])>0) {
data[data$MIME==row$MIME1 & data$VERSION==row$VERSION1 & !is.na(data$VERSION) & !is.na(data$MIME),]$MIME <- row$MIME2
data[data$MIME==row$MIME2 & data$VERSION==row$VERSION1 & !is.na(data$VERSION) & !is.na(data$MIME),]$VERSION <- row$VERSION2
}
}
data
}
loadCollectionProfiles <- function(start, end, dataset, rules) {
#names <- paste(years, dataset, sep="")
data <- data.frame(YEAR=character(), MIME=character(), VERSION=character(), COUNT=character())
for (i in start:end) {
d <- read.table(paste("data/",i,dataset,sep=""), header=TRUE, sep="\t", stringsAsFactors=FALSE)
d <- applyRules(d,rules)
d <- aggregate(COUNT~MIME+VERSION, data=d , FUN=sum)
d["YEAR"] <- i
data <- rbind(data,d)
}
data
}
plotSeparate <- function(data, toPlot) {
#reg <- list()
Yplot <- seq(0,20,length=100)
reg <- data.frame(MIME=character(), PREDICTIONS=vector());
for (i in 1:nrow(toPlot)) {
row <- toPlot[i,]
mime <- row$MIME
p <- merge(data,row)
if (nrow(p)>0){
plot(p$YEAR, p$PERCENTAGE, xlab="", ylab="", main=paste(row$MIME,row$VERSION), pch=19)
plot(p$AGE, p$PERCENTAGE, xlab="", ylab="", main=paste(row$MIME,row$VERSION), pch=19)
r <- lm(PERCENTAGE~AGE + I(AGE^2) + I(AGE^3) + I(AGE^4) + I(AGE^5) + I(AGE^6), data=p)
reg <- rbind(reg, data.frame(MIME=mime,PREDICITONS=predict(r, newdata=data.frame(AGE=Yplot))))
#plot(p$YEAR, p$PERCENTAGE, main=paste(row$MIME,row$VERSION), pch=19, ann=FALSE)
#plot(p$AGE, p$PERCENTAGE, main=paste(row$MIME,row$VERSION), pch=19, ann=FALSE)
}
}
print(reg)
reg
}
plotReg <- function(reg) {
Yplot <- seq(0,20,length=100)
for (i in 1:length(reg)) {
#row <- reg[i,]
lines(Yplot,predict(reg[[i]], newdata=data.frame(AGE=Yplot)),col="blue")
}
}
clean <- function(releases,data) {
inc <- rep(FALSE,nrow(data))
#remove those which appear before release year
for (i in 1:nrow(data)) {
row <- data[i,]
mime <- row$MIME
yt <- row$YEAR
vt <- row$VERSION
ry <- releases[releases$MEDIATYPE==mime & releases$VERSION==vt,]$YEAR
if (length(ry)>0) {
if (yt>=ry) {
inc[i] <- TRUE
}
}
}
data <- data[inc,]
}
calcPerc <- function(releases, data, aggr) {
perc <- data.frame(MIME=character(), VERSION=character(), PERCENTAGE=character(), YEAR=character(), RELEASE=character(), AGE=character(), stringsAsFactors=FALSE)
for (i in 1:nrow(data)) {
row <- data[i,]
mime <- row$MIME
year <- row$YEAR
version <- row$VERSION
count <- row$COUNT
releaseYear <- releases[releases$MIME==mime & releases$VERSION==version,]$YEAR
if (length(releaseYear)>0) {
total <- aggr[aggr$YEAR==year,]$COUNT
percentage <- count/total
diff = year - releaseYear
if ( diff >= 0 ) {
perc <- rbind(perc, data.frame(MIME=mime, VERSION=version, PERCENTAGE=percentage, YEAR=year, RELEASE=releaseYear, AGE=diff))
}
}
}
perc
}
process <- function(year.versions,year, title) {
#year.versions <- read.table(file1, header=TRUE, sep="\t", stringsAsFactors=FALSE)
#dk.year.versions <- read.table(file2, header=TRUE, sep="\t", stringsAsFactors=FALSE)
releases <- read.table("data/release_years.txt", header=TRUE, sep="\t")
#exclude NA and take only years after year
#t <- year.versions[!is.na(uk.year.versions$VERSION),]
t <- year.versions[!is.na(year.versions$VERSION) & year.versions$YEAR > year,]
t <- clean(releases,t)
#tDk <- dk.year.versions[!is.na(dk.year.versions$VERSION),]
#tDk <- clean(releases,tDk,mime)
#aggregate values by years
aggr <- aggregate(COUNT~YEAR, FUN=sum, data=t)
#aggrDk <- aggregate(COUNT~YEAR, FUN=sum, data=tDk)
list <- calcPerc(releases, t, aggr)
#listDk <- calcPerc(releases, tDk, aggrDk, mime)
print(list$perc)
agregPerc <- aggregate(P~Y, FUN=mean, data=list$perc)
print(agregPerc)
agregMax <- aggregate(P~YR, data=list$perc, FUN=max)
agregMaxMer <- merge(list$perc, agregMax)
print(agregMaxMer)
#agregPercDk <- aggregate(P~Y, FUN=mean, data=listDk$perc)
regres <- lm(P~Y + I(Y^2) + I(Y^3) + I(Y^4) + I(Y^5) + I(Y^6), data=agregPerc)
#regresDk <- lm(P~Y + I(Y^2) + I(Y^3) + I(Y^4) + I(Y^5) + I(Y^6), data=agregPercDk)
Yplot <- seq(0,30,length=100)
#plots
plot(agregMaxMer$YR, agregMaxMer$Y, xlab="years", ylab="years after release", main="agregmax")
plot(list$perc$Y,list$perc$P, xlab="years after release", ylab="percentage", main=title)
plot(agregPerc$Y, agregPerc$P, xlab="years after release", ylab="percentage", main=paste(title, " (mean)"))
lines(Yplot,predict(regres, newdata=data.frame(Y=Yplot)),col="blue")
list$perc
#lines(Yplot,predict(regresUk, newdata=data.frame(Y=Yplot)),col="blue")
#plot(listDk$perc$Y,listDk$perc$P, xlab="years after release", ylab="percentage", main=paste(mime,"in DK data set"))
#plot(agregPercDk$Y, agregPercDk$P, xlab="years after release", ylab="percentage", main=paste(mime,"in DK data set (mean)"))
#lines(Yplot,predict(regresDk, newdata=data.frame(Y=Yplot)),col="blue")
# library(lattice)
# print(xyplot(percYears$P~percYears$Y, pch=19, groups=percYears$V, auto.key=TRUE, cex=1.5))
#
#
# library(ggplot2)
# print(ggplot(perc, aes(x=YR, y=P, group=V,fill=V)) + geom_area(position="stack"))
#
#bubble plot
# radius <- sqrt(list$perc$P/pi)
# col <- match(list$perc$V,releases$VERSION)
# symbols(list$perc$YR, list$perc$Y, circles=radius, inches=0.35, fg="white", bg="red", xlab="Year", ylab="Release")
}