process-data.R~ 7.6 KB
Newer Older
Erwan Bousse's avatar
Erwan Bousse committed
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
library(reshape2)
library(scales)


initImage <- function(name, extension) {
    if(extension=="svg")
        svg(filename=paste(name,".svg", sep=""))
    else
        pdf(file=paste(name,".pdf", sep=""))
}


getMemoryUsed <- function(data, mmname, cloningname) {
        value = data[data$MetamodelName==mmname & data$CloningTechnique==cloningname, c('MemoryUsed')]
        return(value)
}


computeMemoryGainCreator <- function(rawdata, cloningName) {

    numberClonesColumn = which(colnames(rawdata)=="NumberOfClones")
    totalMemoryColumn = which(colnames(rawdata)=="MemoryUsed")
    nameColumn = which(colnames(rawdata)=="MetamodelName")

    computeMemoryRatio <- function(row) {
        totalMemory <- as.integer(row[totalMemoryColumn])
        name <- as.character(row[nameColumn])
        otherCloningMemory = getMemoryUsed(rawdata, name, cloningName)
        return (1-totalMemory/otherCloningMemory)
    }
    
    # We return the function that can process each row
    return(computeMemoryRatio)
}



preprocessData <- function (rawdata) {

	# We merge the columns cloningtechnique and light (to create "LightDeep" for instance)
	rawdata$CloningTechnique = paste(rawdata$Light, rawdata$CloningTechnique, sep="")
	
	# We compute the gain compared to three out of four techniques
    rawdataWithoutLabels <- matrix(as.matrix(rawdata), ncol = ncol(rawdata), dimnames = NULL)
    
	rawdata$GainDeep = apply(rawdataWithoutLabels,1,computeMemoryGainCreator(rawdata, 'Deep'))
    rawdata$GainLightDeep = apply(rawdataWithoutLabels,1,computeMemoryGainCreator(rawdata, 'LightDeep'))
	rawdata$GainMutClassOnly = apply(rawdataWithoutLabels,1,computeMemoryGainCreator(rawdata, 'MutClassOnly'))

	# Filtering required columns and required lines
	#filtered = rawdata[, c(measure,'CloningTechnique', variable, 'MetamodelName', 'NumberOfClones')]

	# Getting the list of cloning techniques, in the right order
	techniques = unique(rawdata$CloningTechnique)

	# Enforcing the order of the cloning techniques column
	# https://stackoverflow.com/questions/19710986/how-to-make-acast-preserve-order-of-variable-in-reshape2
	rawdata$CloningTechnique = factor(rawdata$CloningTechnique, techniques)

    return(rawdata)

}



#
# Creates a barplot that compares a given metamodel on one aspect (memory or time) for numerous "number of clones" values
#
plotNumberOfClones <- function(rawdata, metamodelname, minvalue, maxvalue, measure, title){

    prefiltered = preprocessData(rawdata,measure,'NumberOfClones')
    filtered = prefiltered[prefiltered$MetamodelName==metamodelname & prefiltered$NumberOfClones<=maxvalue & prefiltered$NumberOfClones>=minvalue, c(measure,'CloningTechnique', 'NumberOfClones')]

	# Transform the table nicely: NumberOfClones becomes lines, and CloningTechniques columns
	# Means that we want to compare "cloningtechniques" regarding "memory" for each "numberofclones"
	result = dcast(filtered,CloningTechnique~NumberOfClones,value.var=measure)

	# We store the column with the name of the cloning techniques, for the legend, and we delete it
	legendc = result$CloningTechnique
	result$CloningTechnique = NULL

	# We plot with bars, and we put a legend
	name = paste(metamodelname,"_",minvalue,"-",maxvalue,"_clones_",measure, sep="")
	formats = c("svg")#,"pdf")
	
	for (format in formats) {
	    initImage(name,format)
        barplot(as.matrix(result), main=title, xlab= "Number of clones", ylab=measure,beside=TRUE, col=rainbow(length(legendc)))
	    legend("topleft", as.vector(legendc), cex=1, bty="n", fill=rainbow(length(legendc)));
	}
	
	return(result)
}




plotStuff <- function(rawdata, measure, variable, numberOfClones, cloning, maxX, maxY, title) {
    myxlim = NULL
    if (maxX > 0) {
        myxlim = c(0,maxX)
    }
    myylim = NULL
    if (maxY > 0) {
        myylim = c(0,maxY)
    }
    
    myxlab=variable
    if (variable == "MutClassCompShareableClassesRatio") {
        myxlab = "ratio of classes tagged completely shareable \n(objectsSharing tagger)"
    }
    if (variable == "DeepMeanShareablePropertiesInShareableClasses") {
        myxlab = "properties tagged shareable per class tagged completely shareable \n(noObjectsSharing tagger)"
    }
    if (variable == "MutClassMeanShareablePropertiesInShareableClasses") {
        myxlab = "amount of properties tagged shareable per class tagged completely shareable \n(objectsSharing tagger)"
    }
    
    myylab=measure
    if (variable == "GainDeep") {
        myylab = "memory gain over Deep"
    }
    if (variable == "GainLightDeep") {
        myylab = "memory gain over ShareProperties"
    }
    if (variable == "GainMutClassOnly") {
        myylab = "memory gain over ShareObjects"
    }



    data = preprocessData(rawdata)
    mutclassonly = data[data$CloningTechnique==cloning,]
    initImage(paste(cloning,measure),'svg')
    plot(mutclassonly[,c(variable)], mutclassonly[,c(measure)],ylim=myylim,   pch=15, xlab=myxlab, xlim=myxlim, ylab=myylab, yaxt="n", main=title)
    axis(2, at=pretty(mutclassonly[,c(measure)]), lab=paste0(pretty(mutclassonly[,c(measure)]) * 100,"%"), las=TRUE)
}
    



arg = commandArgs(TRUE)
# Parsing CSV file
myrawdata = read.csv(arg)

#plotNumberOfClones(myrawdata, "youpitest1", 0, 10, 'MemoryUsed')
#plotNumberOfClones(myrawdata, "youpitest1", 100, 2000, 'MemoryUsed')
#plotNumberOfClones(myrawdata, "youpitest1", 1000, 10000, 'MemoryUsed')
#plotNumberOfClones(myrawdata, "youpitest1", 0, 10, 'TimeSpent')
#plotNumberOfClones(myrawdata, "youpitest1", 100, 2000, 'TimeSpent')
#plotNumberOfClones(myrawdata, "youpitest1", 1000, 10000, 'TimeSpent')

#plotNumberOfClones(myrawdata, "youpitest1", 1000, 1000, 'MemoryUsed')
#plotNumberOfClones(myrawdata, "youpitest1", 1000, 1000, 'TimeSpent')



#plotNumberOfClones(myrawdata, "youpitest1", 100, 2000, 'MemoryUsed', "Well designed MM")
#plotNumberOfClones(myrawdata, "youpitest1", 1000, 10000, 'MemoryUsed', "Well designed MM")

#plotNumberOfClones(myrawdata, "youpitest2", 100, 2000, 'MemoryUsed', "Well designed MM")
#plotNumberOfClones(myrawdata, "youpitest2", 1000, 10000, 'MemoryUsed', "Well designed MM")
#plotNumberOfClones(myrawdata, "youpitest2", 0, 10, 'TimeSpent', "Well designed MM")
#plotNumberOfClones(myrawdata, "youpitest2", 100, 2000, 'TimeSpent', "Well designed MM")
#plotNumberOfClones(myrawdata, "youpitest2", 1000, 10000, 'TimeSpent', "Well designed MM")

#plotNumberOfClones(myrawdata, "youpitest1", 0, 10, 'MemoryUsed', "")
#plotNumberOfClones(myrawdata, "youpitest2", 0, 10, 'MemoryUsed', "")
#plotNumberOfClones(myrawdata, "youpitest3", 0, 10, 'MemoryUsed', "")

#plotNumberOfClones(myrawdata, "youpitest1", 0, 10, 'GainDeep', "")
#plotNumberOfClones(myrawdata, "youpitest2", 0, 10, 'GainDeep', "")
#plotNumberOfClones(myrawdata, "youpitest3", 0, 10, 'GainDeep', "")


plotStuff(
    myrawdata, 
    'GainDeep', 
    'MutClassCompShareableClassesRatio', 
    '10', 
    'MutClassOnly', 
    1, 1, 
    "Memory gain of ShareObjects compared to Deep\nwith varying ratio of classes tagged completely shareable")

plotStuff(myrawdata, 'GainLightDeep', 'MutClassCompShareableClassesRatio', '10', 'LightMutClassOnly', 1, 1, "Memory gain of ShareBoth compared to ShareProperties \nwith varying ratio of classes tagged completely shareable")

plotStuff(myrawdata, 'GainDeep', 'DeepMeanShareablePropertiesInShareableClasses', '10', 'LightDeep', -1, 1, "Memory gain of ShareProperties compared to Deep \n with varying amount of properties tagged shareable \n per class tagged completely shareable")

plotStuff(myrawdata, 'GainMutClassOnly', 'MutClassMeanShareablePropertiesInShareableClasses', '10', 'LightMutClassOnly', -1, 1, "Memory gain of ShareBoth compared to ShareObjects \n with varying amount of properties tagged shareable \n per class tagged completely shareable")