source: trunk/CrossPare/src/de/ugoe/cs/cpdp/loader/AbstractFolderLoader.java @ 133

Last change on this file since 133 was 132, checked in by sherbold, 8 years ago
  • rather intrusive and large change to correctly evaluate AUCEC in case metrics are modified. The effort is now stored directly with a software version and it is the duty of the loader to specify the review effort for each instance. This required changes to the execution strategiey, data loading, and evaluation process.
  • Property svn:mime-type set to text/plain
File size: 3.8 KB
Line 
1// Copyright 2015 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.cpdp.loader;
16
17import java.io.File;
18import java.util.ArrayList;
19import java.util.LinkedList;
20import java.util.List;
21
22import weka.core.Attribute;
23import weka.core.Instances;
24
25import de.ugoe.cs.cpdp.versions.SoftwareVersion;
26
27/**
28 * Abstract class for loading data from a folder. The subfolders of a defined folder define the
29 * projects, the file contained in the subfolder are the versions of a project.
30 *
31 * @author Steffen Herbold
32 */
33public abstract class AbstractFolderLoader implements IVersionLoader {
34
35    /**
36     * Path of the data.
37     */
38    protected String path = "";
39
40    /**
41     * @see de.ugoe.cs.cpdp.loader.IVersionLoader#setLocation(java.lang.String)
42     */
43    @Override
44    public void setLocation(String location) {
45        path = location;
46    }
47
48    /**
49     * @see de.ugoe.cs.cpdp.loader.IVersionLoader#load()
50     */
51    @Override
52    public List<SoftwareVersion> load() {
53        final List<SoftwareVersion> versions = new LinkedList<SoftwareVersion>();
54
55        final File dataDir = new File(path);
56        final SingleVersionLoader instancesLoader = getSingleLoader();
57        if (dataDir.listFiles() == null) {
58            return versions;
59        }
60        for (File projectDir : dataDir.listFiles()) {
61            if (projectDir.isDirectory()) {
62                String projectName = projectDir.getName();
63                if (projectDir.listFiles() != null) {
64                    for (File versionFile : projectDir.listFiles()) {
65                        if (versionFile.isFile() &&
66                            instancesLoader.filenameFilter(versionFile.getName()))
67                        {
68                            Instances data = instancesLoader.load(versionFile);
69                            String versionName = data.relationName();
70                            List<Double> efforts = getEfforts(data);
71                            versions.add(new SoftwareVersion(projectName, versionName, data, efforts));
72                        }
73                    }
74                }
75            }
76        }
77        return versions;
78    }
79   
80    private List<Double> getEfforts(Instances data) {
81        // attribute in the JURECZKO data and default
82        Attribute effortAtt = data.attribute("loc");
83        if (effortAtt == null) {
84            // attribute in the NASA/SOFTMINE/MDP data
85            effortAtt = data.attribute("LOC_EXECUTABLE");
86        }
87        if (effortAtt == null) {
88            // attribute in the AEEEM data
89            effortAtt = data.attribute("numberOfLinesOfCode");
90        }
91        if (effortAtt == null) {
92            // attribute in the RELINK data
93            effortAtt = data.attribute("CountLineCodeExe");
94        }
95        if( effortAtt == null ) {
96            return null;
97        }
98        List<Double> efforts = new ArrayList<>(data.size());
99        for( int i=0; i<data.size(); i++ ) {
100            efforts.add(data.get(i).value(effortAtt));
101        }
102        return efforts;
103    }
104
105    /**
106     * Returns the concrete {@link SingleVersionLoader} to be used with this folder loader.
107     *
108     * @return
109     */
110    abstract protected SingleVersionLoader getSingleLoader();
111}
Note: See TracBrowser for help on using the repository browser.