| 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 |
|
|---|
| 15 | package de.ugoe.cs.cpdp.loader;
|
|---|
| 16 |
|
|---|
| 17 | import java.io.File;
|
|---|
| 18 | import java.util.ArrayList;
|
|---|
| 19 | import java.util.LinkedList;
|
|---|
| 20 | import java.util.List;
|
|---|
| 21 |
|
|---|
| 22 | import weka.core.Attribute;
|
|---|
| 23 | import weka.core.Instances;
|
|---|
| 24 |
|
|---|
| 25 | import 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 | */
|
|---|
| 33 | public 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
|
|---|
| 72 | .add(new SoftwareVersion(projectName, versionName, data, efforts));
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 | return versions;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | /**
|
|---|
| 82 | * <p>
|
|---|
| 83 | * Sets the efforts for the instances
|
|---|
| 84 | * </p>
|
|---|
| 85 | *
|
|---|
| 86 | * @param data
|
|---|
| 87 | * the data
|
|---|
| 88 | * @return
|
|---|
| 89 | */
|
|---|
| 90 | private List<Double> getEfforts(Instances data) {
|
|---|
| 91 | // attribute in the JURECZKO data and default
|
|---|
| 92 | Attribute effortAtt = data.attribute("loc");
|
|---|
| 93 | if (effortAtt == null) {
|
|---|
| 94 | // attribute in the NASA/SOFTMINE/MDP data
|
|---|
| 95 | effortAtt = data.attribute("LOC_EXECUTABLE");
|
|---|
| 96 | }
|
|---|
| 97 | if (effortAtt == null) {
|
|---|
| 98 | // attribute in the AEEEM data
|
|---|
| 99 | effortAtt = data.attribute("numberOfLinesOfCode");
|
|---|
| 100 | }
|
|---|
| 101 | if (effortAtt == null) {
|
|---|
| 102 | // attribute in the RELINK data
|
|---|
| 103 | effortAtt = data.attribute("CountLineCodeExe");
|
|---|
| 104 | }
|
|---|
| 105 | if (effortAtt == null) {
|
|---|
| 106 | return null;
|
|---|
| 107 | }
|
|---|
| 108 | List<Double> efforts = new ArrayList<>(data.size());
|
|---|
| 109 | for (int i = 0; i < data.size(); i++) {
|
|---|
| 110 | efforts.add(data.get(i).value(effortAtt));
|
|---|
| 111 | }
|
|---|
| 112 | return efforts;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | /**
|
|---|
| 116 | * Returns the concrete {@link SingleVersionLoader} to be used with this folder loader.
|
|---|
| 117 | *
|
|---|
| 118 | * @return the version loader
|
|---|
| 119 | */
|
|---|
| 120 | abstract protected SingleVersionLoader getSingleLoader();
|
|---|
| 121 | }
|
|---|