diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7..f2248a5 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/CohortConceptGraphs.java b/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/CohortConceptGraphs.java
index 32c485c..0d223e4 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/CohortConceptGraphs.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/CohortConceptGraphs.java
@@ -48,8 +48,8 @@ public CohortConceptGraphs(ConceptGraph structureGraph, List summaries){
- this(structureGraph,summaries);
+ public CohortConceptGraphs(String filename, ConceptGraph structureGraph, List responses){
+ this(structureGraph,responses);
//TODO: call CohortConceptGraphsRecord
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/ConceptGraph.java b/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/ConceptGraph.java
index e5067ce..ac71546 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/ConceptGraph.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/ConceptGraph.java
@@ -6,7 +6,7 @@
import edu.ithaca.dragon.tecmap.io.record.LinkRecord;
import edu.ithaca.dragon.tecmap.learningresource.AssessmentItem;
import edu.ithaca.dragon.tecmap.learningresource.AssessmentItemResponse;
-import edu.ithaca.dragon.tecmap.learningresource.LearningResource;
+import edu.ithaca.dragon.tecmap.learningresource.LearningMaterial;
import edu.ithaca.dragon.tecmap.learningresource.LearningResourceType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -24,7 +24,7 @@ public class ConceptGraph {
// but also can be quickly looked up here (also allows checks for duplicates).
private Map nodeMap;
private Map assessmentItemMap;
- private Map learningMaterialMap;
+ private Map learningMaterialMap;
public ConceptGraph(ConceptGraphRecord structureDef){
@@ -34,14 +34,14 @@ public ConceptGraph(ConceptGraphRecord structureDef){
this.learningMaterialMap = new HashMap<>();
}
- public ConceptGraph(ConceptGraphRecord structureDef, List lolRecords){
+ public ConceptGraph(ConceptGraphRecord structureDef, List learningResourceRecords){
this(structureDef);
- addLearningResourcesFromRecords(lolRecords);
+ addLearningResourcesFromRecords(learningResourceRecords);
}
- public ConceptGraph(ConceptGraphRecord structureDef, List lolRecords, List AssessmentItemResponses){
- this(structureDef, lolRecords);
- addAssessmentItemResponses(AssessmentItemResponses);
+ public ConceptGraph(ConceptGraphRecord structureDef, List learningResourceRecords, List assessmentItemResponses){
+ this(structureDef, learningResourceRecords);
+ addAssessmentItemResponses(assessmentItemResponses);
}
/**
@@ -62,14 +62,14 @@ public ConceptGraph(ConceptGraph other, String newName){
* e.g., when you are making a tree copy
* @param other a graph to copy
* @param newName the new name of the graph
- * @param loMap a map of learning objects, which can be in any state of populated/not populated. This function will
+ * @param aiMap a map of learning objects, which can be in any state of populated/not populated. This function will
* connect the existing learning obejcts, or add any new ones necessary
*/
- public ConceptGraph(ConceptGraph other, String newName, HashMap loMap, HashMap lmMap){
+ public ConceptGraph(ConceptGraph other, String newName, HashMap aiMap, HashMap lmMap){
this.name = newName;
this.roots = new ArrayList<>();
nodeMap = new HashMap<>();
- assessmentItemMap = loMap;
+ assessmentItemMap = aiMap;
learningMaterialMap = lmMap;
//recursively copy entire graph
@@ -85,7 +85,7 @@ public ConceptGraph(ConceptGraph other, String newName, HashMap rootsIn, String name, Map AssessmentItemMap, Map learningMaterialMap, Map nodeMap){
+ public ConceptGraph(List rootsIn, String name, Map AssessmentItemMap, Map learningMaterialMap, Map nodeMap){
this.name = name;
this.assessmentItemMap = AssessmentItemMap;
this.learningMaterialMap = learningMaterialMap;
@@ -159,7 +159,7 @@ public void addLearningResourcesFromRecords(List learnin
if (record.isType(LearningResourceType.INFORMATION) || record.isType(LearningResourceType.PRACTICE)){
//since we've already added possibly an assessment for this record, remove it (if it were there) so the list can be used to create the material directly from the list
record.getResourceTypes().remove(LearningResourceType.ASSESSMENT);
- linkLearningMaterials(new LearningResource(record), record.getConceptIds());
+ linkLearningMaterials(new LearningMaterial(record), record.getConceptIds());
}
}
}
@@ -174,11 +174,11 @@ public void addLearningResourcesFromRecords(List learnin
*/
public int linkAssessmentItem (AssessmentItem toLink, Collection conceptIds){
int numAdded = 0;
- if (assessmentItemMap.get(toLink.getId()) != null){
- logger.warn(toLink.getId()+" already exists in this graph. Nothing was added.");
+ if (assessmentItemMap.get(toLink.getText()) != null){
+ logger.warn(toLink.getText()+" already exists in this graph. Nothing was added.");
return -1;
}
- assessmentItemMap.put(toLink.getId(), toLink);
+ assessmentItemMap.put(toLink.getText(), toLink);
for (String id: conceptIds){
if(nodeMap.get(id) != null){
numAdded++;
@@ -199,13 +199,13 @@ public int linkAssessmentItem (AssessmentItem toLink, Collection concept
* @post the LearningMaterial is added to the graph's map, and to all associated Concept's AssessmentItem maps
* @return the number of concepts the LearningMaterial was added to, or -1 if the LearningMaterial already exists
*/
- public int linkLearningMaterials(LearningResource toLink, Collection conceptIds){
+ public int linkLearningMaterials(LearningMaterial toLink, Collection conceptIds){
int numAdded = 0;
- if (learningMaterialMap.get(toLink.getId()) != null){
- logger.warn(toLink.getId()+" already exists in this graph. Nothing was added.");
+ if (learningMaterialMap.get(toLink.getText()) != null){
+ logger.warn(toLink.getText()+" already exists in this graph. Nothing was added.");
return -1;
}
- learningMaterialMap.put(toLink.getId(), toLink);
+ learningMaterialMap.put(toLink.getText(), toLink);
for (String id: conceptIds){
if(nodeMap.get(id) != null){
numAdded++;
@@ -226,13 +226,14 @@ public int linkLearningMaterials(LearningResource toLink, Collection con
*/
public void addAssessmentItemResponses(List assessmentItemResponses) {
for (AssessmentItemResponse response : assessmentItemResponses){
- AssessmentItem assessmentItem = assessmentItemMap.get(response.getLearningObjectId());
+ AssessmentItem assessmentItem = assessmentItemMap.get(response.getAssessmentItemText());
if (assessmentItem != null){
assessmentItem.addResponse(response);
}
else {
- logger.warn("No AssessmentItem:" + response.getLearningObjectId() + " for response: " + response.toString());
+ logger.warn("No AssessmentItem: " + response.getAssessmentItemText() + " for response: " + response.toString());
//TODO: maybe make a new list of unconnected learning objects???
+ Thread.dumpStack();
}
}
}
@@ -244,11 +245,11 @@ public void addAssessmentItemResponses(List assessmentIt
public Map buildDirectConceptLinkCount(){
Map directConceptLinkCountMap = new HashMap<>();
for (ConceptNode node: nodeMap.values()){
- for (LearningResource learningMaterial : node.getLearningMaterialMap().values()){
- if(directConceptLinkCountMap.containsKey(learningMaterial.getId())){
- directConceptLinkCountMap.put(learningMaterial.getId(),directConceptLinkCountMap.get(learningMaterial.getId())+1);
+ for (LearningMaterial learningMaterial : node.getLearningMaterialMap().values()){
+ if(directConceptLinkCountMap.containsKey(learningMaterial.getText())){
+ directConceptLinkCountMap.put(learningMaterial.getText(),directConceptLinkCountMap.get(learningMaterial.getText())+1);
}else{
- directConceptLinkCountMap.put(learningMaterial.getId(), 1);
+ directConceptLinkCountMap.put(learningMaterial.getText(), 1);
}
}
}
@@ -260,12 +261,11 @@ public Map buildDirectConceptLinkCount(){
* @return a map from id -> pathCount to the given conceptNode
*/
public Map buildLearningResourcePathCount(String node) {
-
ConceptNode findNode = findNodeById(node);
if (findNode != null) {
- Map idToPathCount = new HashMap<>();
- findNode.buildLearningMaterialPathCount(idToPathCount);
- return idToPathCount;
+ Map textToPathCount = new HashMap<>();
+ findNode.buildLearningMaterialPathCount(textToPathCount);
+ return textToPathCount;
}else{
logger.warn("buildLearningMaterialPathCount:" + node + " is not found in the graph");
return null;
@@ -316,8 +316,8 @@ public double calcTotalKnowledgeEstimate(String startingNodeId){
public int responsesCount(){
int total = 0;
- for (AssessmentItem lo : assessmentItemMap.values()){
- total += lo.getResponses().size();
+ for (AssessmentItem assessmentItem : assessmentItemMap.values()){
+ total += assessmentItem.getResponses().size();
}
return total;
}
@@ -358,7 +358,7 @@ public void calcDataImportance(){
* @return
*/
public List getAssessmentsBelowAssessmentID(String assessmentId) {
- List nodesWithAssessmentId = getNodesWithAssessmentId(assessmentId);
+ List nodesWithAssessmentId = getNodesWithAssessmentText(assessmentId);
List assessmentNodesPathLengths = new ArrayList<>();
for (ConceptNode node : nodesWithAssessmentId) {
@@ -373,24 +373,24 @@ public List getAssessmentsBelowAssessmentID(String assessmentId) {
}
/**
- * Gets list of assessmentItems that are x steps below the highest occurrence of the given assessmentId for each root
- * @param assessmentId
+ * Gets list of assessmentItems that are x steps below the highest occurrence of the given assessmentText for each root
+ * @param assessmentText
* @param stepsDown number of steps to take
* @return List of assessments x steps down, null if there are negative stepsDown
*/
- public List getAssessmentsBelowAssessmentID(String assessmentId, int stepsDown) {
+ public List getAssessmentsBelowAssessmentID(String assessmentText, int stepsDown) {
if (stepsDown < 0) {
return null;
}
- List nodesWithAssessmentId = getNodesWithAssessmentId(assessmentId);
+ List nodesWithAssessmentText = getNodesWithAssessmentText(assessmentText);
- //Dictates that an assessmentId will only be included once
+ //Dictates that an assessmentText will only be included once
Set assessmentsBelow = new HashSet<>();
- for (ConceptNode node : nodesWithAssessmentId) {
+ for (ConceptNode node : nodesWithAssessmentText) {
getAssessmentsBelowNode(assessmentsBelow, node, stepsDown);
for (AssessmentItem item : node.getAssessmentItemMap().values()) {
- if (!assessmentsBelow.contains(item.getId()) && !item.getId().equals(assessmentId)) {
- assessmentsBelow.add(item.getId());
+ if (!assessmentsBelow.contains(item.getText()) && !item.getText().equals(assessmentText)) {
+ assessmentsBelow.add(item.getText());
}
}
}
@@ -399,21 +399,21 @@ public List getAssessmentsBelowAssessmentID(String assessmentId, int ste
}
/**
- * Finds the nodes from the graph with the given assessmentId in its list of assessments
- * @param assessmentId
+ * Finds the nodes from the graph with the given assessmentText in its list of assessments
+ * @param assessmentText
* @return
*/
- public List getNodesWithAssessmentId(String assessmentId) {
- List nodesWithAssessmentId = new ArrayList<>();
- //Find the nodes with the given AssessmentId
+ public List getNodesWithAssessmentText(String assessmentText) {
+ List nodesWithAssessmentText = new ArrayList<>();
+ //Find the nodes with the given AssessmentText
for (ConceptNode node : nodeMap.values()) {
for (AssessmentItem item : node.getAssessmentItemMap().values()) {
- if (item.getId().equals(assessmentId)) {
- nodesWithAssessmentId.add(node);
+ if (item.getText().equals(assessmentText)) {
+ nodesWithAssessmentText.add(node);
}
}
}
- return nodesWithAssessmentId;
+ return nodesWithAssessmentText;
}
/**
@@ -430,7 +430,7 @@ public Set getAssessmentsBelowNode(Set assessmentList, ConceptNo
} else {
for (ConceptNode child : startNode.getChildren()) {
for (AssessmentItem item : child.getAssessmentItemMap().values()) {
- assessmentList.add(item.getId());
+ assessmentList.add(item.getText());
}
assessmentList = getAssessmentsBelowNode(assessmentList, child, stepsToTake-1);
}
@@ -452,7 +452,7 @@ public Map getAssessmentItemMap() {
return assessmentItemMap;
}
- public Map getLearningMaterialMap() {
+ public Map getLearningMaterialMap() {
return learningMaterialMap;
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/ConceptNode.java b/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/ConceptNode.java
index 12f7784..680c897 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/ConceptNode.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/ConceptNode.java
@@ -4,7 +4,7 @@
import edu.ithaca.dragon.tecmap.io.record.ConceptRecord;
import edu.ithaca.dragon.tecmap.io.record.LinkRecord;
import edu.ithaca.dragon.tecmap.learningresource.AssessmentItem;
-import edu.ithaca.dragon.tecmap.learningresource.LearningResource;
+import edu.ithaca.dragon.tecmap.learningresource.LearningMaterial;
import java.util.*;
@@ -17,8 +17,8 @@ public class ConceptNode {
private double knowledgeDistanceFromAvg;
private double dataImportance;
- private Map learningObjectMap; //These same LearningObjects might also be held by other nodes
- private Map learningMaterialMap; //These same LearningObjects might also be held by other nodes
+ private Map assessmentItemMap; //These same LearningObjects might also be held by other nodes
+ private Map learningMaterialMap; //These same LearningObjects might also be held by other nodes
List children;
@@ -39,7 +39,7 @@ public ConceptNode(ConceptRecord conceptRecord) {
this.dataImportance = conceptRecord.getDataImportance();
this.children = new ArrayList<>();
- this.learningObjectMap = new HashMap<>();
+ this.assessmentItemMap = new HashMap<>();
this.learningMaterialMap = new HashMap<>();
}
@@ -53,7 +53,7 @@ public ConceptNode(ConceptRecord conceptRecord) {
* @param graphLearningMaterialMap the current learningMaterialMap for the graph that this node will be a part of
* @post all contents of this new node are set to new copies of the data from , and all children are also copied
*/
- public ConceptNode(ConceptNode nodeToCopy, Map graphNodeMap, Map graphLearningObjectMap, Map graphLearningMaterialMap){
+ public ConceptNode(ConceptNode nodeToCopy, Map graphNodeMap, Map graphLearningObjectMap, Map graphLearningMaterialMap){
copyContents(nodeToCopy, graphLearningObjectMap, graphLearningMaterialMap);
//recursively copy children
@@ -81,7 +81,7 @@ public ConceptNode(ConceptNode nodeToCopy, Map graphNodeMap
* @param graphLearningMaterialMap the current learningMaterialMap for the graph that this node will be a part of
* @post all contents of this new node are set to new copies of the data from nodeToCopy
*/
- public ConceptNode(String newId, ConceptNode nodeToCopy, Map graphLearningObjectMap, Map graphLearningMaterialMap){
+ public ConceptNode(String newId, ConceptNode nodeToCopy, Map graphLearningObjectMap, Map graphLearningMaterialMap){
copyContents(nodeToCopy, graphLearningObjectMap, graphLearningMaterialMap);
this.id = newId;
}
@@ -89,13 +89,13 @@ public ConceptNode(String newId, ConceptNode nodeToCopy, Map graphLearningObjectMap, Map graphLearningMaterialMap){
+ private void copyContents(ConceptNode nodeToCopy, Map assessmentItemMap, Map learningMaterialMap){
this.id = nodeToCopy.id;
this.label = nodeToCopy.label;
this.knowledgeEstimate = nodeToCopy.knowledgeEstimate;
@@ -103,27 +103,27 @@ private void copyContents(ConceptNode nodeToCopy, Map gr
this.dataImportance = nodeToCopy.dataImportance;
//Complicated because it is a graph, so it should only copy LearningObjects if they haven't already been created
- this.learningObjectMap = new HashMap<>();
- for (Map.Entry entry: nodeToCopy.learningObjectMap.entrySet()){
+ this.assessmentItemMap = new HashMap<>();
+ for (Map.Entry entry: nodeToCopy.assessmentItemMap.entrySet()){
//check the map first to see if that learningObject has already been created
- AssessmentItem newColumnItem = graphLearningObjectMap.get(entry.getKey());
+ AssessmentItem newColumnItem = assessmentItemMap.get(entry.getKey());
if (newColumnItem == null) {
newColumnItem = new AssessmentItem(entry.getValue());
- graphLearningObjectMap.put(entry.getKey(), newColumnItem);
+ assessmentItemMap.put(entry.getKey(), newColumnItem);
}
- this.learningObjectMap.put(entry.getKey(), newColumnItem);
+ this.assessmentItemMap.put(entry.getKey(), newColumnItem);
}
this.learningMaterialMap = new HashMap<>();
- for (Map.Entry entry: nodeToCopy.learningMaterialMap.entrySet()){
+ for (Map.Entry entry: nodeToCopy.learningMaterialMap.entrySet()){
//check the map first to see if that learningMaterial has already been created
- LearningResource newLearningObject = graphLearningMaterialMap.get(entry.getKey());
- if (newLearningObject == null) {
- newLearningObject = new LearningResource(entry.getValue());
- graphLearningMaterialMap.put(entry.getKey(), newLearningObject);
+ LearningMaterial newLearningMaterial = learningMaterialMap.get(entry.getKey());
+ if (newLearningMaterial == null) {
+ newLearningMaterial = new LearningMaterial(entry.getValue());
+ learningMaterialMap.put(entry.getKey(), newLearningMaterial);
}
- this.learningMaterialMap.put(entry.getKey(), newLearningObject);
+ this.learningMaterialMap.put(entry.getKey(), newLearningMaterial);
}
this.children = new ArrayList<>();
}
@@ -155,20 +155,20 @@ public double totalKnowledgeEstimateForThisAndAllDescendants(List nodesA
/**
* for each LearningMaterial, calculates the number of paths to that learning material from the given node
- * @param idToPathCount a map of id -> countOfPaths to be added to recursively (empty when recursion starts)
+ * @param textToPathCount a map of text -> countOfPaths to be added to recursively (empty when recursion starts)
* @post the map with this node and all children with updated counts
*/
- public void buildLearningMaterialPathCount(Map idToPathCount){
- for (LearningResource material : this.learningMaterialMap.values()) {
- if (idToPathCount.containsKey(material.getId())){
- idToPathCount.put(material.getId() ,idToPathCount.get(material.getId())+1);
+ public void buildLearningMaterialPathCount(Map textToPathCount){
+ for (LearningMaterial material : this.learningMaterialMap.values()) {
+ if (textToPathCount.containsKey(material.getText())){
+ textToPathCount.put(material.getText(), textToPathCount.get(material.getText()) + 1);
}else{
- idToPathCount.put(material.getId(), 1);
+ textToPathCount.put(material.getText(), 1);
}
}
//go to each of the children and call on child so that the child node's learning objects will be added.
for(ConceptNode child: children){
- child.buildLearningMaterialPathCount(idToPathCount);
+ child.buildLearningMaterialPathCount(textToPathCount);
}
}
@@ -196,7 +196,7 @@ public boolean isAncestorOf(ConceptNode possibleDescendant){
*/
public void calcDataImportance(){
double tempDI=0;
- for(AssessmentItem columnItem : learningObjectMap.values()){
+ for(AssessmentItem columnItem : assessmentItemMap.values()){
tempDI+= columnItem.getDataImportance();
}
@@ -214,7 +214,7 @@ public void calcDataImportance(){
public void calcKnowledgeEstimate() {
//calculate estimate from learning objects directly connected to this node
double currentConceptEstimate = 0;
- for (AssessmentItem columnItem : learningObjectMap.values()){
+ for (AssessmentItem columnItem : assessmentItemMap.values()){
currentConceptEstimate += columnItem.calcKnowledgeEstimate()* columnItem.getDataImportance();
}
@@ -271,11 +271,11 @@ public int getLongestPathToLeaf() {
////////////////// Simple Methods //////////////////////
public void addAssessmentItem(AssessmentItem columnItem) {
- learningObjectMap.put(columnItem.getId(), columnItem);
+ assessmentItemMap.put(columnItem.getText(), columnItem);
}
- public void addLearningMaterial(LearningResource learningObject) {
- learningMaterialMap.put(learningObject.getId(), learningObject);
+ public void addLearningMaterial(LearningMaterial learningMaterial) {
+ learningMaterialMap.put(learningMaterial.getText(), learningMaterial);
}
public void addChild(ConceptNode child){
@@ -313,10 +313,10 @@ public double getKnowledgeDistanceFromAvg(){
public double getDataImportance() { return dataImportance; }
public Map getAssessmentItemMap() {
- return learningObjectMap;
+ return assessmentItemMap;
}
- public Map getLearningMaterialMap() {
+ public Map getLearningMaterialMap() {
return learningMaterialMap;
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/TreeConverter.java b/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/TreeConverter.java
index 5d32a97..766fe81 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/TreeConverter.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/conceptgraph/TreeConverter.java
@@ -1,7 +1,7 @@
package edu.ithaca.dragon.tecmap.conceptgraph;
import edu.ithaca.dragon.tecmap.learningresource.AssessmentItem;
-import edu.ithaca.dragon.tecmap.learningresource.LearningResource;
+import edu.ithaca.dragon.tecmap.learningresource.LearningMaterial;
import java.util.ArrayList;
import java.util.HashMap;
@@ -17,7 +17,7 @@ public class TreeConverter {
public static ConceptGraph makeTreeCopy(ConceptGraph graphToCopy){
Map resourceMap = AssessmentItem.deepCopyLearningObjectMap(graphToCopy.getAssessmentItemMap());
- Map materialMap = LearningResource.deepCopyLearningResourceMap(graphToCopy.getLearningMaterialMap());
+ Map materialMap = LearningMaterial.deepCopyLearningMaterialMap(graphToCopy.getLearningMaterialMap());
Map nodeMap = new HashMap<>();
@@ -30,7 +30,7 @@ public static ConceptGraph makeTreeCopy(ConceptGraph graphToCopy){
}
- public static ConceptNode makeTreeNodeCopy(ConceptNode nodeToMakeTreeCopyOf, HashMap> labelToListOfIds, MapnodeMap, Map resourceMap, Map materialMap){
+ public static ConceptNode makeTreeNodeCopy(ConceptNode nodeToMakeTreeCopyOf, HashMap> labelToListOfIds, MapnodeMap, Map resourceMap, Map materialMap){
ConceptNode nodeCopy;
List idsList = labelToListOfIds.get(nodeToMakeTreeCopyOf.getLabel());
//if there are no copies, make a new list to store all the copies and add it to the map
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/data/TecmapFileDatastore.java b/src/main/java/edu/ithaca/dragon/tecmap/data/TecmapFileDatastore.java
index c86bc5e..360508e 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/data/TecmapFileDatastore.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/data/TecmapFileDatastore.java
@@ -1,5 +1,6 @@
package edu.ithaca.dragon.tecmap.data;
+import com.opencsv.exceptions.CsvException;
import edu.ithaca.dragon.tecmap.Settings;
import edu.ithaca.dragon.tecmap.Tecmap;
import edu.ithaca.dragon.tecmap.TecmapAPI;
@@ -86,8 +87,8 @@ public TecmapAPI retrieveTecmapForId(String idToRetrieve, TecmapState desiredSta
if (desiredState == TecmapState.AssessmentLinked) {
return new Tecmap(new ConceptGraph(ConceptGraphRecord.buildFromJson(files.getGraphFile())),
LearningResourceRecord.createLearningResourceRecordsFromJsonFiles(files.getResourceFiles()),
- //TODO: hardcoded to sakai csv, need to hold a list of CSVReaders, or the information about which kind of reader it is...
- ReaderTools.assessmentItemsFromCSVList(2, files.getAssessmentFiles()),
+ //TODO: hardcoded to canvas csv, need to hold a list of CSVReaders, or the information about which kind of reader it is...
+ ReaderTools.assessmentItemsFromCSVList(files.getAssessmentFiles()),
AssessmentItemResponse.createAssessmentItemResponses(files.getAssessmentFiles())
);
}
@@ -95,8 +96,8 @@ else if (desiredState == TecmapState.AssessmentNoLinks) {
return new Tecmap(new ConceptGraph(ConceptGraphRecord.buildFromJson(files.getGraphFile())),
null,
- //TODO: hardcoded to sakai csv, need to hold a list of CSVReaders, or the information about which kind of reader it is...
- ReaderTools.assessmentItemsFromCSVList(2, files.getAssessmentFiles()),
+ //TODO: hardcoded to canvas csv, need to hold a list of CSVReaders, or the information about which kind of reader it is...
+ ReaderTools.assessmentItemsFromCSVList(files.getAssessmentFiles()),
AssessmentItemResponse.createAssessmentItemResponses(files.getAssessmentFiles())
);
}
@@ -114,7 +115,7 @@ else if (desiredState == TecmapState.OnlyGraphStructureState) {
throw new RuntimeException("Unrecognized state desired, can't retrieve tecmap");
}
}
- catch (IOException e){
+ catch (IOException | CsvException e){
logger.warn("IOException when trying to create map for id: "+ idToRetrieve +"\tError:", e);
return null;
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/Json.java b/src/main/java/edu/ithaca/dragon/tecmap/io/Json.java
index 6a4ee63..f9c81e1 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/Json.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/Json.java
@@ -13,7 +13,7 @@ public class Json {
public static String toJsonString(Object objectToSerialize) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
- return mapper.writeValueAsString( objectToSerialize);
+ return mapper.writeValueAsString(objectToSerialize);
}
public static void toJsonFile(String filename, Object objectToSerialize) throws IOException {
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/Anonymizer.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/Anonymizer.java
index 6deb3ff..f5af19b 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/Anonymizer.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/Anonymizer.java
@@ -10,13 +10,33 @@ public class Anonymizer implements CsvProcessor{
private int numToUseNext;
private Map realId2anonId;
private Map realname2anonName;
- private int gradeStartColumnIndex; // canvas 3, sakai 2
+ private final int nameStartRowIndex;
+ private final int nameColumnIndex;
+ private final int idColumnIndex;
- public Anonymizer(int gradeStartColumnIndex){
- numToUseNext =1;
+ // Default values
+ private static final int DEFAULT_NAME_COLUMN_INDEX = 0; // canvas format
+ private static final int DEFAULT_ID_COLUMN_INDEX = 1; // canvas format
+
+ public Anonymizer(int nameStartRowIndex, int nameColumnIndex, int idColumnIndex){
+ numToUseNext = 1;
realId2anonId = new HashMap<>();
realname2anonName = new HashMap<>();
- this.gradeStartColumnIndex = gradeStartColumnIndex;
+ this.nameStartRowIndex = nameStartRowIndex;
+ this.nameColumnIndex = nameColumnIndex;
+ this.idColumnIndex = idColumnIndex;
+ }
+
+ public Anonymizer(int nameStartRowIndex) {
+ this(nameStartRowIndex, DEFAULT_NAME_COLUMN_INDEX, DEFAULT_ID_COLUMN_INDEX);
+ }
+
+ public static Anonymizer AnonymizerCreator(String filepathAndName, int nameStartRowIndex, int nameColumnIndex, int idColumnIndex) {
+ try {
+ return Json.fromJsonFile(filepathAndName, Anonymizer.class);
+ } catch (IOException e) {
+ return new Anonymizer(nameStartRowIndex, nameColumnIndex, idColumnIndex);
+ }
}
public static Anonymizer AnonymizerCreator(String filepathAndName, int gradeStartIndex) {
@@ -28,11 +48,11 @@ public static Anonymizer AnonymizerCreator(String filepathAndName, int gradeStar
}
public void anonymize(List rows) {
- Collections.shuffle(rows.subList(gradeStartColumnIndex, rows.size()));
- for(String[] row : rows.subList(gradeStartColumnIndex, rows.size())){
- if (row.length >1) { // canvas id column is 1
- row[0] = getAnonStr(row[0], realname2anonName, "student", numToUseNext);
- row[1] = getAnonStr(row[1], realId2anonId, "s", numToUseNext);
+ Collections.shuffle(rows.subList(nameStartRowIndex, rows.size()));
+ for(String[] row : rows.subList(nameStartRowIndex, rows.size())){
+ if (row.length > 1) {
+ row[nameColumnIndex] = getAnonStr(row[0], realname2anonName, "student", numToUseNext);
+ row[idColumnIndex] = getAnonStr(row[1], realId2anonId, "s", numToUseNext);
numToUseNext++;
}
}
@@ -68,7 +88,7 @@ public void writeToFile(String filepath) throws IOException {
Json.toJsonFile(filepath+this.getClass().getSimpleName()+".json", this);
}
- public int getGradeStartColumnIndex() { return gradeStartColumnIndex; }
+ public int getNameStartRowIndex() { return nameStartRowIndex; }
public int getNumToUseNext() {
return numToUseNext;
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CanvasConverter.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CanvasConverter.java
new file mode 100644
index 0000000..f6d9bbc
--- /dev/null
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CanvasConverter.java
@@ -0,0 +1,32 @@
+package edu.ithaca.dragon.tecmap.io.reader;
+
+import java.io.IOException;
+import java.util.List;
+
+public class CanvasConverter implements CsvProcessor {
+
+ public static void canvasConverter(List rows) {
+ CreateMaxScoreRow.createMaxScoreRow(rows);
+ SwapNameAndIDColumn.swapNameAndIDColumn(rows);
+ MoveGradeStartColumnIndex.moveGradeStartColumnIndex(rows);
+ }
+ @Override
+ public boolean shouldProcessFile(String filename) {
+ return true;
+ }
+
+ @Override
+ public void processRows(List rows) {
+ canvasConverter(rows);
+ }
+
+ @Override
+ public String createProcessedFilename(String origFilename) {
+ return "";
+ }
+
+ @Override
+ public void writeToFile(String filepath) throws IOException {
+
+ }
+}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CanvasReader.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CanvasReader.java
index c7167d1..1375227 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CanvasReader.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CanvasReader.java
@@ -3,9 +3,11 @@
import java.io.IOException;
import java.util.List;
+
public class CanvasReader extends TecmapCSVReader {
- public CanvasReader(String filename)throws IOException {
- super(filename, 4, 3);
+
+ public CanvasReader(List rows, List processors) throws IOException {
+ super(rows, processors);
}
/**
@@ -14,8 +16,8 @@ public CanvasReader(String filename)throws IOException {
* @return the ID of the student
*/
@Override
- public String getIDForAStudent(List dataLine) {
- return dataLine.get(1);
+ public String getIDForAStudent(String[] dataLine) {
+ return dataLine[1];
}
/**
@@ -24,7 +26,7 @@ public String getIDForAStudent(List dataLine) {
* @return the name of the student
*/
@Override
- public String getNameForAStudent(List dataLine) {
- return dataLine.get(0);
+ public String getNameForAStudent(String[] dataLine) {
+ return dataLine[0];
}
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ConvertToSakaiLabel.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ConvertToSakaiLabel.java
deleted file mode 100644
index e773419..0000000
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ConvertToSakaiLabel.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package edu.ithaca.dragon.tecmap.io.reader;
-
-import java.io.IOException;
-import java.util.List;
-
-public class ConvertToSakaiLabel implements CsvProcessor {
-
- public static void addPointTotalsToQuestionLabels(String[] questionLabelsRow, String[] pointTotalsRow, int gradeStartColumnIndex){
- for(int colIdx=gradeStartColumnIndex; colIdx rows) {
- }
-
- @Override
- public String createProcessedFilename(String origFilename) {
- return "";
- }
-
- @Override
- public void writeToFile(String filepath) throws IOException {
-
- }
-}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CreateMaxScoreRow.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CreateMaxScoreRow.java
new file mode 100644
index 0000000..2f38dd1
--- /dev/null
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CreateMaxScoreRow.java
@@ -0,0 +1,55 @@
+package edu.ithaca.dragon.tecmap.io.reader;
+
+import java.io.IOException;
+import java.util.List;
+
+public class CreateMaxScoreRow implements CsvProcessor {
+ // build a new row of point possible (canvas format)
+ public static void createMaxScoreRow(List rows) {
+ String[] newRow = new String[rows.get(0).length];
+ newRow[0] = "Points Possible";
+ for (int i = 0; i < rows.get(0).length; i++) {
+ String question = rows.get(0)[i];
+ int begin = question.lastIndexOf('[');
+ int end = question.lastIndexOf(']');
+ // Check if square brackets are not found, then look for parentheses
+ if (begin < 0 || end < 0) {
+ begin = question.lastIndexOf('(');
+ end = question.lastIndexOf(')');
+ }
+ // If either pair is found, extract the max score and update the question
+ if (begin >= 0 && end >= 0) {
+ String maxScoreStr = question.substring(begin + 1, end);
+ rows.get(0)[i] = question.substring(0, begin - 1).trim(); // begin - 1 to make sure no space followed
+ newRow[i] = maxScoreStr;
+ }
+ }
+ // Fill the empty spots ""
+ for (int i = 1; i < newRow.length; i++) {
+ if (newRow[i] == null || newRow[i].isEmpty()) {
+ newRow[i] = "";
+ }
+ }
+ rows.add(2, newRow);
+ }
+
+ @Override
+ public boolean shouldProcessFile(String filename) {
+ return true;
+ }
+
+ @Override
+ public void processRows(List rows) {
+ createMaxScoreRow(rows);
+ }
+
+ @Override
+ public String createProcessedFilename(String origFilename) {
+ return "";
+ }
+
+ @Override
+ public void writeToFile(String filepath) throws IOException {
+
+ }
+}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvRepresentation.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvFileLibrary.java
similarity index 97%
rename from src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvRepresentation.java
rename to src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvFileLibrary.java
index 0c84bfa..d6a8d0a 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvRepresentation.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvFileLibrary.java
@@ -8,7 +8,7 @@
import java.util.ArrayList;
import java.util.List;
-public class CsvRepresentation {
+public class CsvFileLibrary {
public static List parseRowsFromFile(String filename) throws IOException, CsvException {
List list = new ArrayList<>();
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvProcessingMain.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvProcessingMain.java
index dac1019..9da2337 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvProcessingMain.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvProcessingMain.java
@@ -8,7 +8,7 @@ public class CsvProcessingMain {
public static void main(String[] args){
List processors = new ArrayList<>();
//processors.add(new PointsOffConverter());
- processors.add(Anonymizer.AnonymizerCreator("src/main/resources/anonHere/anonymizer.json", 2));
+ processors.add(Anonymizer.AnonymizerCreator("src/main/resources/anonHere/anonymizer.json", 2, 1, 0));
for (CsvProcessor processor : processors){
try {
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvProcessor.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvProcessor.java
index cd51c45..e776cc4 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvProcessor.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/CsvProcessor.java
@@ -18,9 +18,9 @@ public interface CsvProcessor {
static void processFilesInDirectory(CsvProcessor processor, String directoryToProcess) throws IOException, CsvException {
for (String filename : allCsvFilesInDirectory(directoryToProcess)) {
if (processor.shouldProcessFile(filename)) {
- List rows = CsvRepresentation.parseRowsFromFile(directoryToProcess+filename);
+ List rows = CsvFileLibrary.parseRowsFromFile(directoryToProcess+filename);
processor.processRows(rows);
- CsvRepresentation.writeRowsToFile(rows, directoryToProcess+processor.createProcessedFilename(filename));
+ CsvFileLibrary.writeRowsToFile(rows, directoryToProcess+processor.createProcessedFilename(filename));
}
}
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/MoveGradeStartColumnIndex.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/MoveGradeStartColumnIndex.java
new file mode 100644
index 0000000..95f89f0
--- /dev/null
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/MoveGradeStartColumnIndex.java
@@ -0,0 +1,46 @@
+package edu.ithaca.dragon.tecmap.io.reader;
+
+import java.io.IOException;
+import java.util.List;
+
+public class MoveGradeStartColumnIndex implements CsvProcessor {
+
+ public static void moveGradeStartColumnIndex(List rows) {
+ for (int i = 0; i < rows.size(); i++) {
+ String[] row = rows.get(i);
+ String[] newRow = new String[row.length + 2];
+ if (row.length > 1) {
+ // copy elements before index 2
+ System.arraycopy(row, 0, newRow, 0, 2);
+ // insert empty string at position of 2 and 3
+ for (int j = 2; j < 4; j++) {
+ newRow[j] = "";
+ }
+ // copy elements after GradeStartColumnIndex 2
+ System.arraycopy(row, 2, newRow, 4, row.length - 2);
+ // Replace old row with the new row
+ rows.set(i, newRow);
+ }
+ }
+ }
+
+ @Override
+ public boolean shouldProcessFile(String filename) {
+ return true;
+ }
+
+ @Override
+ public void processRows(List rows) {
+ moveGradeStartColumnIndex(rows);
+ }
+
+ @Override
+ public String createProcessedFilename(String origFilename) {
+ return "";
+ }
+
+ @Override
+ public void writeToFile(String filepath) throws IOException {
+
+ }
+}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/PointsOffConverter.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/PointsOffConverter.java
index fc8a56f..7d455cc 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/PointsOffConverter.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/PointsOffConverter.java
@@ -6,7 +6,6 @@
public class PointsOffConverter implements CsvProcessor {
/**
- *
* @throws NumberFormatException if cells can't be converted to ints or doubles
*/
public static void convertFromPointsOffToTotalPoints(List rows){
@@ -24,7 +23,7 @@ public static void convertFromPointsOffToTotalPoints(List rows){
}
String[] newBlankRow = new String[1];
newBlankRow[0]="";
- rows.set(1, newBlankRow );
+ rows.set(1, newBlankRow);
}
@Override
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ReaderTools.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ReaderTools.java
index b5bb5b1..fdd13dc 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ReaderTools.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ReaderTools.java
@@ -1,5 +1,8 @@
package edu.ithaca.dragon.tecmap.io.reader;
+import com.opencsv.exceptions.CsvException;
+import edu.ithaca.dragon.tecmap.Settings;
+import edu.ithaca.dragon.tecmap.io.record.LearningResourceRecord;
import edu.ithaca.dragon.tecmap.learningresource.AssessmentItem;
import java.io.BufferedReader;
@@ -7,81 +10,37 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
/**
* This class is a tool box class for CSV reader, these static functions are called by TecmapCSVReader
- * to to data specific and line reading tasks.
+ * to data specific and line reading tasks.
* Created by Ryan on 10/25/2017.
*/
public class ReaderTools {
-
- /**
- * staticLineToList takes a given CSV file and reads each line in the file and adds it to a list
- * to be returned.
- *
- * @param filename the name of the file being read
- * @return lineList, contains a list of each line in the file
- */
- public static ArrayList> staticLineToList(String filename){
- ArrayList> lineList = new ArrayList>();
- try {
- String line;
- BufferedReader csvBuffer = new BufferedReader(new FileReader(filename));
- //Takes the file being read in and calls a function to convert each line into a list split at
- //every comma, then push all the lists returned into a list of lists lineList[line][item in line]
- while ((line = csvBuffer.readLine()) != null) {
- lineList.add(lineToList(line));
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return lineList;
- }
-
/**
* This function take the list of assessments in a given file with their max grades in the title, This program takes
* the name of the assessment separate from the max grade and returns a list of the assessmentItems
- *
- * @param indexMark the column index point where the recording of assessments and grades start for the rest of the file
- * @param singleList the line of the file that contains the list of assessments with the maximum grade
+ * @param rows all rows of the file
* @return aiList -> a list of each assessment and its maximum grade
*/
- public static List assessmentItemsFromList(int indexMark, List singleList) {
- int i = indexMark;
+ public static List assessmentItemsFromList(List rows) {
List aiList = new ArrayList<>();
- while(i= 0 && end >= 0) {
- String maxScoreStr = question.substring(begin + 1, end);
+ for (int i = 4; i < rows.get(0).length; i++) {
+ String text = rows.get(0)[i];
+ String maxScoreStr = rows.get(2)[i];
+ String id = LearningResourceRecord.generateUniqueID(null);
+ if (!maxScoreStr.isEmpty()) {
double maxScore = Double.parseDouble(maxScoreStr);
- question = question.substring(0, begin - 1);
- AssessmentItem columnItem = new AssessmentItem(question);
- columnItem.setMaxPossibleKnowledgeEstimate(maxScore);
+ AssessmentItem columnItem = new AssessmentItem(id, text, maxScore);
aiList.add(columnItem);
}
else {
- //logger.error("No max score found for string:"+question+"\t defaulting to 1, which is probably wrong");
- AssessmentItem columnItem = new AssessmentItem(question);
- columnItem.setMaxPossibleKnowledgeEstimate(1);
+ AssessmentItem columnItem = new AssessmentItem(id, text);
aiList.add(columnItem);
}
- i++;
}
return aiList;
}
@@ -92,13 +51,14 @@ else if (indexMark == 4){ // canvas format
* @param csvfiles
* @return a list of all AssessmentItem across all files
*/
- public static List assessmentItemsFromCSVList(int indexMark, List csvfiles){
+ public static List assessmentItemsFromCSVList(List csvfiles) throws IOException, CsvException {
List fullAIList = new ArrayList<>();
- //Each csvfile has their AIs searched
+ // Each csvfile has their AIs searched
for(String file: csvfiles){
- ArrayList> lineList = ReaderTools.staticLineToList(file);
- List aiList = ReaderTools.assessmentItemsFromList(indexMark,lineList.get(0));
+ List rows = CsvFileLibrary.parseRowsFromFile(file);
+ CanvasConverter.canvasConverter(rows);
+ List aiList = ReaderTools.assessmentItemsFromList(rows);
//adding current csvfile's LOs to the full list of AIs
for(AssessmentItem columnItem : aiList) {
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/SakaiReader.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/SakaiReader.java
index 1f65d44..6f1d589 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/SakaiReader.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/SakaiReader.java
@@ -1,6 +1,9 @@
package edu.ithaca.dragon.tecmap.io.reader;
+import com.opencsv.exceptions.CsvException;
+
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -9,8 +12,8 @@
* Created by Ryan on 11/9/2017.
*/
public class SakaiReader extends TecmapCSVReader {
- public SakaiReader(String filename)throws IOException{
- super(filename, 2, 1);
+ public SakaiReader(List rows, List processors) throws IOException, CsvException {
+ super(rows, processors);
}
/**
@@ -19,8 +22,8 @@ public SakaiReader(String filename)throws IOException{
* @return the ID of the student
*/
@Override
- public String getIDForAStudent(List dataLine) {
- return dataLine.get(0);
+ public String getIDForAStudent(String[] dataLine) {
+ return dataLine[0];
}
/**
@@ -29,7 +32,7 @@ public String getIDForAStudent(List dataLine) {
* @return the name of the student
*/
@Override
- public String getNameForAStudent(List dataLine) {
- return dataLine.get(1);
+ public String getNameForAStudent(String[] dataLine) {
+ return dataLine[1]; // 1
}
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/SwapNameAndIDColumn.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/SwapNameAndIDColumn.java
new file mode 100644
index 0000000..3a46a3d
--- /dev/null
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/SwapNameAndIDColumn.java
@@ -0,0 +1,38 @@
+package edu.ithaca.dragon.tecmap.io.reader;
+
+
+import java.io.IOException;
+import java.util.List;
+
+public class SwapNameAndIDColumn implements CsvProcessor {
+
+ public static void swapNameAndIDColumn(List rows) {
+ for (String[] row : rows) {
+ if ((row[0] != null && !row[0].isEmpty()) && (row[1] != null && !row[1].isEmpty())) {
+ String temp = row[0];
+ row[0] = row[1];
+ row[1] = temp;
+ }
+ }
+ }
+
+ @Override
+ public boolean shouldProcessFile(String filename) {
+ return true;
+ }
+
+ @Override
+ public void processRows(List rows) {
+ swapNameAndIDColumn(rows);
+ }
+
+ @Override
+ public String createProcessedFilename(String origFilename) {
+ return "";
+ }
+
+ @Override
+ public void writeToFile(String filepath) throws IOException {
+
+ }
+}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/TecmapCSVReader.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/TecmapCSVReader.java
index a6a1531..4c5cb3d 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/TecmapCSVReader.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/TecmapCSVReader.java
@@ -6,6 +6,7 @@
* Created by willsuchanek on 3/6/17.
*/
+import edu.ithaca.dragon.tecmap.io.record.LearningResourceRecord;
import edu.ithaca.dragon.tecmap.learningresource.AssessmentItem;
import edu.ithaca.dragon.tecmap.learningresource.AssessmentItemResponse;
import edu.ithaca.dragon.tecmap.learningresource.ManualGradedResponse;
@@ -19,108 +20,90 @@
import java.util.List;
-public abstract class TecmapCSVReader { // differences between reader and processor
- // maybe take a list of csv processors, and list of string[] then delete the file
- // change convert to sakai label to processor
+public abstract class TecmapCSVReader {
static Logger logger = LogManager.getLogger(TecmapCSVReader.class);
- String filename;
- BufferedReader csvBuffer = null;
List columnItemList;
List manualGradedResponseList;
- ReaderTools toolBox = new ReaderTools();
- int gradeStartColumnIndex;
- int nameStartRowIndex;
- List studentNames = new ArrayList<>();
+ List studentNames;
/**
- * This function is passed a filename of a gradebook directly exported from Sakai's built in gradebook.
+ * This function is passed a filename of a gradebook directly exported from Canvas's built in gradebook.
* (See DataCSVExample.csv in test/testresources/io for proper file format example)
- * this function also takes an index mark that will determine where grades are first recorded in the
- * CSV file.
- * @param filename
- * @param gradeStartColumnIndex
+ * @param rows a list of rows from the file
+ * @param processors a list of csv processors
*/
- public TecmapCSVReader(String filename, int gradeStartColumnIndex, int nameStartRowIndex)throws IOException{
- this.filename = filename;
+ public TecmapCSVReader(List rows, List processors) throws IOException{
manualGradedResponseList = new ArrayList<>();
columnItemList = new ArrayList<>();
- this.gradeStartColumnIndex = gradeStartColumnIndex;
- this.nameStartRowIndex = nameStartRowIndex;
- try {
- String line;
- this.csvBuffer = new BufferedReader(new FileReader(filename));
- ArrayList> lineList = new ArrayList<>();
- //Takes the file being read in and calls a function to convert each line into a list split at
- //every comma, then pust all the lists returned into a list of lists lineList[line][item in line]
- while((line = this.csvBuffer.readLine())!= null){
- ArrayList potentialLineList = toolBox.lineToList(line);
- if (potentialLineList.size() > 1){
- lineList.add(potentialLineList);
- }
- }
-
-// The first list in the list of lists is the assessments (questions) so we go through the first line and
-// pull out all the learning objects and put them into the columnItemList
- this.columnItemList = toolBox.assessmentItemsFromList(gradeStartColumnIndex, lineList.get(0));
- for (int i = nameStartRowIndex; i < lineList.size(); i++) {
- studentNames.add(getNameForAStudent(lineList.get(i)));
- try {
- //goes through and adds all the questions to their proper learning object, as well as adds them to
- //the general list of manual graded responses
- createManualGradedResponseList(lineList.get(i));
- } catch (NullPointerException e) {
- System.out.println("No Responses added to one or more LearningObjects");
- }
- }
- } catch (IOException e) {
-// e.printStackTrace();
- }
+ studentNames = new ArrayList<>();
+ readFiles(rows, processors);
}
public List getManualGradedResponses(){return this.manualGradedResponseList;}
public List getManualGradedLearningObjects(){return this.columnItemList;}
- public abstract String getIDForAStudent(List dataLine);
+ public abstract String getIDForAStudent(String[] dataLine);
- public abstract String getNameForAStudent(List dataLine);
+ public abstract String getNameForAStudent(String[] dataLine);
/**
* This function takes a list of student data and creates a manual graded response for that user
- * @param singleList - a list with each line in the csv file holding LORs
- * @throws NullPointerException if the ManualGradedResponse is null
+ * @param row - a row in the file
*/
- public void createManualGradedResponseList(ArrayList singleList)throws NullPointerException{
- int i = gradeStartColumnIndex;
- String stdID = getIDForAStudent(singleList);
- if (columnItemList.size() + gradeStartColumnIndex < singleList.size()) {
- logger.error("More data than learning objects on line for id:" + stdID);
- } else if (columnItemList.size() + gradeStartColumnIndex > singleList.size()) {
- logger.warn("More learning objects than data on line for id:" + stdID);
+ public void createManualGradedResponseList(String[] row) throws Exception {
+ int i = 4;
+ String stdID = getIDForAStudent(row);
+ if (columnItemList.size() + 4 < row.length) {
+ logger.error("More data than learning objects on line for id: {}", stdID);
+ } else if (columnItemList.size() + 4 > row.length) {
+ logger.warn("More learning objects than data on line for id: {}", stdID);
}
//need to make sure we don't go out of bounds on either list
- while (i < singleList.size() && i < columnItemList.size() + gradeStartColumnIndex) {
- AssessmentItem currentColumnItem = this.columnItemList.get(i - gradeStartColumnIndex);
- String qid = currentColumnItem.getId();
- if (!("".equals(singleList.get(i)))) {
+ while (i < row.length && i < columnItemList.size() + 4) {
+ AssessmentItem currentColumnItem = this.columnItemList.get(i - 4);
+ String assessmentItemId = currentColumnItem.getId();
+ String assessmentItemText = currentColumnItem.getText();
+ if (!("".equals(row[i]))) {
double studentGrade;
- String number = toolBox.pullNumber(singleList.get(i));
- if (number.equals("")){
- studentGrade = 0.0;
- }
- else{
+ String number = ReaderTools.pullNumber(row[i]);
+ if (!number.isEmpty()){
studentGrade = Double.parseDouble(number);
}
- ManualGradedResponse response = new ManualGradedResponse(qid, currentColumnItem.getMaxPossibleKnowledgeEstimate(), studentGrade, stdID);
- if(response != null) {
- currentColumnItem.addResponse(response);
- this.manualGradedResponseList.add(response);
- }else{
- throw new NullPointerException();
+ // raise exception if there is anything other than numbers
+ else {
+ throw new Exception("Typos where grades are expected.");
}
+ ManualGradedResponse response = new ManualGradedResponse(assessmentItemId, assessmentItemText, currentColumnItem.getMaxPossibleKnowledgeEstimate(), studentGrade, stdID);
+ currentColumnItem.addResponse(response);
+ this.manualGradedResponseList.add(response);
}
i++;
}
}
+
+ public void readFiles(List rows, List processors) {
+// The first list in the list of lists is the assessments (questions) so we go through the first line and
+// pull out all the learning objects and put them into the columnItemList
+ if (!processors.isEmpty()) {
+ for (CsvProcessor processor : processors) {
+ processor.processRows(rows);
+ }
+ }
+ columnItemList = ReaderTools.assessmentItemsFromList(rows);
+ for (int i = 3; i < rows.size(); i++) {
+ String[] row = rows.get(i);
+ if (row.length > 1) {
+ studentNames.add(getNameForAStudent(row));
+ try {
+ //goes through and adds all the questions to their proper learning object, as well as adds them to
+ //the general list of manual graded responses
+ createManualGradedResponseList(rows.get(i));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ZybooksReader.java b/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ZybooksReader.java
deleted file mode 100644
index 29cc5a8..0000000
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/reader/ZybooksReader.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package edu.ithaca.dragon.tecmap.io.reader;
-
-import java.io.IOException;
-import java.util.List;
-
-/**
- *This is tha child class for zybooks files, with its specific function for reading in the student names
- * it will call super to the parent class, TecmapCSVReader, and pass the filename and the specific gradeColumnIndexMark.
- *
- * Created by Ryan on 10/4/2017.
- */
-
-public class ZybooksReader extends TecmapCSVReader {
- public ZybooksReader(String filename)throws IOException{
- super(filename, 5, 1);
- }
-
- /**
- * This function takes in a line that holds all the info for a specific student and returns the full student name.
- * @param dataLine - the line of the students info and grades
- * @return the full name of the student
- */
- @Override
- public String getIDForAStudent(List dataLine){
- String stdID = dataLine.get(0) + " " + dataLine.get(1);
- return stdID;
- }
-
- /**
- * This function takes in a line that holds all the info for a specific student and returns the
- * student name.
- * @param dataLine - the line of the students info and grades
- * @return the name of the student
- */
- @Override
- public String getNameForAStudent(List dataLine){
- return dataLine.get(1);
- }
-}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/record/ConceptGraphRecord.java b/src/main/java/edu/ithaca/dragon/tecmap/io/record/ConceptGraphRecord.java
index a91f632..5c8e015 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/record/ConceptGraphRecord.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/record/ConceptGraphRecord.java
@@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
+import edu.ithaca.dragon.tecmap.io.reader.CreateMaxScoreRow;
import java.io.File;
import java.io.IOException;
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/record/LearningResourceRecord.java b/src/main/java/edu/ithaca/dragon/tecmap/io/record/LearningResourceRecord.java
index 65810d6..9423f15 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/record/LearningResourceRecord.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/record/LearningResourceRecord.java
@@ -1,5 +1,8 @@
package edu.ithaca.dragon.tecmap.io.record;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -12,33 +15,44 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Random;
/**
* Created by willsuchanek on 4/10/17.
*/
public class LearningResourceRecord {
-
- private String learningResourceId;
+ @JsonIgnore
+ private String id;
private Collection resourceTypes;
private Collection conceptIds;
private double dataImportance;
private double maxPossibleKnowledgeEstimate;
-
- public LearningResourceRecord(String learningResourceId, Collection resourceTypes, Collection conceptIds, double maxPossibleKnowledgeEstimate, double dataImportance){
- this.learningResourceId = learningResourceId;
- this.resourceTypes = new ArrayList<>(resourceTypes);
- this.conceptIds = new ArrayList<>(conceptIds);
+ private String text;
+
+// public LearningResourceRecord(Collection resourceTypes, Collection conceptIds,
+// double maxPossibleKnowledgeEstimate, double dataImportance, String text){
+ @JsonCreator
+ public LearningResourceRecord(
+ @JsonProperty("resourceTypes") Collection resourceTypes,
+ @JsonProperty("conceptIds") Collection conceptIds,
+ @JsonProperty("maxPossibleKnowledgeEstimate") double maxPossibleKnowledgeEstimate,
+ @JsonProperty("dataImportance") double dataImportance,
+ @JsonProperty("text") String text){
+ this.resourceTypes = (resourceTypes != null) ? new ArrayList<>(resourceTypes) : new ArrayList<>();
+ this.conceptIds = (conceptIds != null) ? new ArrayList<>(conceptIds) : new ArrayList<>();
this.dataImportance = dataImportance;
this.maxPossibleKnowledgeEstimate = maxPossibleKnowledgeEstimate;
+ this.text = text;
+ this.id = generateUniqueID(this.conceptIds);
}
public LearningResourceRecord(AssessmentItem assessment){
- this( assessment.getId(), LearningResourceType.getDefaultResourceTypes() , new ArrayList<>(), assessment.getMaxPossibleKnowledgeEstimate(), assessment.getDataImportance());
+ this(LearningResourceType.getDefaultResourceTypes() , new ArrayList<>(), assessment.getMaxPossibleKnowledgeEstimate(), assessment.getDataImportance(), assessment.getText());
}
// default constructor for JSON
- public LearningResourceRecord(){
- this("", new ArrayList<>(), new ArrayList<>(), 1, 0);
+ public LearningResourceRecord(String text){
+ this(new ArrayList<>(), new ArrayList<>(), 1, 0, text);
}
public static List createLearningResourceRecordsFromJsonFiles(List filenames) throws IOException {
@@ -57,11 +71,11 @@ public static List createLearningResourceRecordsFromJson
}
public static List createLearningResourceRecordsFromAssessmentItems(Collection columnItems){
- List lolrList = new ArrayList();
+ List lrrList = new ArrayList();
for(AssessmentItem columnItem : columnItems){
- lolrList.add( new LearningResourceRecord(columnItem));
+ lrrList.add( new LearningResourceRecord(columnItem));
}
- return lolrList;
+ return lrrList;
}
public static void resourceRecordsToJSON(Collection lolrList, String filename)throws IOException{
@@ -74,17 +88,19 @@ public boolean isType(LearningResourceType typeToCheck){
return resourceTypes.contains(typeToCheck);
}
- public String getLearningResourceId(){ return this.learningResourceId; }
- public Collection getConceptIds(){ return this.conceptIds; }
+ public String getId(){ return this.id; }
+ public Collection getConceptIds(){ return conceptIds; }
public double getDataImportance(){ return this.dataImportance; }
public double getMaxPossibleKnowledgeEstimate(){ return this.maxPossibleKnowledgeEstimate;}
- public void setLearningResourceId(String lo){this.learningResourceId = lo;}
+ public void setId(String lo){this.id = lo;}
public void setConceptIds(List conceptIds){this.conceptIds=conceptIds;}
public void setDataImportance(double dataImportance){this.dataImportance=dataImportance;}
public void setMaxPossibleKnowledgeEstimate(double maxPossibleKnowledgeEstimate) {this.maxPossibleKnowledgeEstimate = maxPossibleKnowledgeEstimate;}
+ public void setText(String text){this.text = text;}
+ public String getText(){return this.text;}
public void addConceptId(String conceptId){
- this.conceptIds.add(conceptId);
+ conceptIds.add(conceptId);
}
public Collection getResourceTypes() {
@@ -95,14 +111,28 @@ public void setResourceTypes(Collection resourceTypes) {
this.resourceTypes = new ArrayList<>(resourceTypes);
}
+ public static String generateUniqueID(Collection conceptIds) {
+ Random random = new Random();
+ int num = 1 + random.nextInt(10000);
+ StringBuilder concepts = new StringBuilder();
+ if (conceptIds != null) {
+ for (String conceptId : conceptIds) {
+ concepts.append(conceptId.trim());
+ }
+ return concepts + "_PracticeProblem" + num;
+ }
+ return "_PracticeProblem" + num;
+ }
+
public String toString(){
- String out = "(Learning Resource ID: " + this.learningResourceId + " Concept IDs: ";
+ String out = "(Learning Resource Text: " + this.text + " Concept IDs: ";
for (String id : conceptIds){
out+=id + ", ";
}
//remove last comma and space
out = out.substring(0, out.length()-2);
out+=")";
- return out;
+ return out;
}
+
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/io/writer/CSVOutputter.java b/src/main/java/edu/ithaca/dragon/tecmap/io/writer/CSVOutputter.java
index f757da7..2d49d41 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/io/writer/CSVOutputter.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/io/writer/CSVOutputter.java
@@ -30,7 +30,7 @@ public CSVOutputter(String filename, List summaries) thr
toCSV(filename);
}
/**
- * Takes the list of LOR and converts them all into a CSV file based on whether or not they were answered
+ * Takes the list of AIR and converts them all into a CSV file based on whether or not they were answered
* correctly. Read functions to find out more about the formatting (makeCSV())
* @param summaries takes a list of Per User Per Problem Summaries
*/
@@ -55,7 +55,7 @@ public CSVOutputter(List summaries){
//sets "correct" variable to 0 if incorrect and 1 if correct
double correct = summary.calcKnowledgeEstimate();
//gets the right map for the current user of this summary and adds to it
- questionsToAnswer.put(summary.getLearningObjectId(), correct);
+ questionsToAnswer.put(summary.getAssessmentItemText(), correct);
}
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/learningresource/AssessmentItem.java b/src/main/java/edu/ithaca/dragon/tecmap/learningresource/AssessmentItem.java
index 9f2c692..3b6b32e 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/learningresource/AssessmentItem.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/learningresource/AssessmentItem.java
@@ -3,31 +3,34 @@
import edu.ithaca.dragon.tecmap.io.record.LearningResourceRecord;
import edu.ithaca.dragon.tecmap.util.DataUtil;
-import java.lang.reflect.Array;
import java.util.*;
/**
* @author tdragon
* 2/14/17.
*/
+
public class AssessmentItem {
String id;
+ String text;
List responses;
double maxPossibleKnowledgeEstimate;
- public AssessmentItem(String id){
- this (id, 1);
+ public AssessmentItem(String id, String text){
+ this (id, text,1);
}
- public AssessmentItem(String id, double maxPossibleKnowledgeEstimate){
+ public AssessmentItem(String id, String text, double maxPossibleKnowledgeEstimate){
this.id = id;
+ this.text = text;
this.responses = new ArrayList<>();
this.maxPossibleKnowledgeEstimate = maxPossibleKnowledgeEstimate;
}
public AssessmentItem(AssessmentItem other){
this.id = other.id;
+ this.text = other.text;
this.maxPossibleKnowledgeEstimate = other.maxPossibleKnowledgeEstimate;
this.responses = new ArrayList<>();
for (AssessmentItemResponse response : other.responses){
@@ -43,18 +46,19 @@ public AssessmentItem(AssessmentItem other){
//temprary fucntion to get htings working before switching to LearningResourceRecords
public AssessmentItem(LearningResourceRecord record){
- this.id = record.getLearningResourceId();
+ this.id = record.getId();
+ this.text = record.getText();
this.maxPossibleKnowledgeEstimate = record.getMaxPossibleKnowledgeEstimate();
this.responses = new ArrayList<>();
}
public void addResponse(AssessmentItemResponse response){
- if (id.equals(response.getLearningObjectId())) {
+ if (text.equals(response.getAssessmentItemText())) {
responses.add(response);
}
else{
- throw new IllegalArgumentException("Response object id:"+ response.getLearningObjectId()
- + " does not match LearningObjectId:" + id);
+ throw new IllegalArgumentException("AIR text: "+ response.getAssessmentItemText()
+ + " does not match AssessmentItemText: " + text);
}
}
@@ -87,14 +91,16 @@ public static Map deepCopyLearningObjectMap(Map getResponses() {
return responses;
}
+ public String getText() {
+ return text;
+ }
+
+ public String getId() {return id;}
+
public boolean equals(Object other){
if(other == null){
return false;
@@ -102,8 +108,8 @@ public boolean equals(Object other){
if(!AssessmentItem.class.isAssignableFrom(other.getClass())){
return false;
}
- AssessmentItem otherNode = (AssessmentItem) other;
- if(this.id.equals(otherNode.id) && this.responses.equals(otherNode.responses)){
+ AssessmentItem assessmentItem = (AssessmentItem) other;
+ if(this.text.equals(assessmentItem.text) && this.responses.equals(assessmentItem.responses)){
return true;
} else {
return false;
@@ -111,11 +117,11 @@ public boolean equals(Object other){
}
public String toString(){
- return "LO ID:" + id + "\t" + "maxPossKnowEst:" + maxPossibleKnowledgeEstimate + "\t" + responses.toString();
+ return "AI Text: " + text + "\t" + "maxPossKnowEst: " + maxPossibleKnowledgeEstimate + "\t" + responses.toString();
}
public String getSummaryString(){
- return getId() + " Est:" + DataUtil.format(calcKnowledgeEstimate()) + " Imp:" + DataUtil.format(getDataImportance()) + " ResponseCount:" + getResponses().size();
+ return getText() + " Est: " + DataUtil.format(calcKnowledgeEstimate()) + " Imp: " + DataUtil.format(getDataImportance()) + " ResponseCount: " + getResponses().size();
}
public void setMatchingKnowledgeEstimates(Collection columnItems, Map loMap){
@@ -132,12 +138,13 @@ public void setMatchingKnowledgeEstimates(Collection columnItems
public static List buildListFromAssessmentItemResponses(List responses, Map maxKnowledgeEstimates) {
Map assessments = new HashMap<>();
for (AssessmentItemResponse response : responses) {
- String assessmentId = response.getLearningObjectId();
+ String assessmentId = response.getAssessmentItemId();
+ String assessmentText = response.getAssessmentItemText();
if (assessments.containsKey(assessmentId)) {
assessments.get(assessmentId).addResponse(response);
} else {
- double maxKE = maxKnowledgeEstimates.get(assessmentId);
- AssessmentItem newAssessment = new AssessmentItem(assessmentId, maxKE);
+ double maxKE = maxKnowledgeEstimates.get(assessmentText);
+ AssessmentItem newAssessment = new AssessmentItem(assessmentId, assessmentText, maxKE);
newAssessment.addResponse(response);
assessments.put(assessmentId, newAssessment);
}
@@ -159,7 +166,7 @@ public static List getItemResponsesFromAssessmentList(Li
public static List getAssessmentCopyWithoutResponses(List assessmentItems){
List assessmentsListNoResponses = new ArrayList<>();
for(AssessmentItem assessment : assessmentItems){
- AssessmentItem newAssessment = new AssessmentItem(assessment.getId(), assessment.getMaxPossibleKnowledgeEstimate());
+ AssessmentItem newAssessment = new AssessmentItem(assessment.getId(), assessment.getText(), assessment.getMaxPossibleKnowledgeEstimate());
assessmentsListNoResponses.add(newAssessment);
}
return assessmentsListNoResponses;
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/learningresource/AssessmentItemResponse.java b/src/main/java/edu/ithaca/dragon/tecmap/learningresource/AssessmentItemResponse.java
index 08e4fc3..0f62a95 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/learningresource/AssessmentItemResponse.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/learningresource/AssessmentItemResponse.java
@@ -1,7 +1,7 @@
package edu.ithaca.dragon.tecmap.learningresource;
-import edu.ithaca.dragon.tecmap.io.reader.TecmapCSVReader;
-import edu.ithaca.dragon.tecmap.io.reader.SakaiReader;
+import com.opencsv.exceptions.CsvException;
+import edu.ithaca.dragon.tecmap.io.reader.*;
import edu.ithaca.dragon.tecmap.util.DataUtil;
import java.io.IOException;
@@ -17,18 +17,21 @@
public class AssessmentItemResponse {
private String userId;
- private String learningObjectId;
+ private String assessmentItemId;
+ private String assessmentItemText;
private double knowledgeEstimate;
- public AssessmentItemResponse(String userId, String learningObjectId, double knowledgeEstimate) {
+ public AssessmentItemResponse(String userId, String assessmentItemId, String assessmentItemText, double knowledgeEstimate) {
this.userId = userId;
- this.learningObjectId = learningObjectId;
+ this.assessmentItemId = assessmentItemId;
+ this.assessmentItemText = assessmentItemText;
this.knowledgeEstimate = knowledgeEstimate;
}
public AssessmentItemResponse(AssessmentItemResponse other){
this.userId = other.userId;
- this.learningObjectId = other.learningObjectId;
+ this.assessmentItemId = other.assessmentItemId;
+ this.assessmentItemText = other.assessmentItemText;
this.knowledgeEstimate = other.knowledgeEstimate;
}
@@ -49,7 +52,7 @@ public static Map> getUserResponseMap(List<
return userIdToResponses;
}
- public String getLearningObjectId(){ return learningObjectId; }
+ public String getAssessmentItemId(){ return assessmentItemId; }
public double calcKnowledgeEstimate(){
return knowledgeEstimate;
@@ -59,6 +62,7 @@ public String getUserId(){
return userId;
}
+ public String getAssessmentItemText(){ return assessmentItemText; }
public boolean equals(Object other){
if(other == null){
@@ -69,7 +73,7 @@ public boolean equals(Object other){
}
AssessmentItemResponse otherNode = (AssessmentItemResponse) other;
if(this.userId.equals(otherNode.userId) && DataUtil.equalsDoubles(this.knowledgeEstimate, otherNode.knowledgeEstimate)
- && this.learningObjectId.equals(otherNode.learningObjectId)){
+ && this.assessmentItemId.equals(otherNode.assessmentItemId)){
return true;
} else {
return false;
@@ -77,13 +81,16 @@ public boolean equals(Object other){
}
public String toString(){
- return getLearningObjectId() + "\tuser: "+ getUserId() + "\t est: "+ calcKnowledgeEstimate();
+ return getAssessmentItemText() + "\tuser: "+ getUserId() + "\t est: "+ calcKnowledgeEstimate();
}
- public static List createAssessmentItemResponses(List assessmentFiles) throws IOException {
+ public static List createAssessmentItemResponses(List assessmentFiles) throws IOException, CsvException {
List assessments = new ArrayList<>();
for (String aname: assessmentFiles){
- TecmapCSVReader tecmapCsvReader = new SakaiReader(aname);
+ List rows = CsvFileLibrary.parseRowsFromFile(aname);
+ List processors = new ArrayList<>();
+ processors.add(new CanvasConverter());
+ TecmapCSVReader tecmapCsvReader = new CanvasReader(rows, processors);
List temp = tecmapCsvReader.getManualGradedResponses();
assessments.addAll(temp);
}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/learningresource/LearningMaterial.java b/src/main/java/edu/ithaca/dragon/tecmap/learningresource/LearningMaterial.java
new file mode 100644
index 0000000..15276fe
--- /dev/null
+++ b/src/main/java/edu/ithaca/dragon/tecmap/learningresource/LearningMaterial.java
@@ -0,0 +1,41 @@
+package edu.ithaca.dragon.tecmap.learningresource;
+
+import edu.ithaca.dragon.tecmap.io.record.LearningResourceRecord;
+import lombok.Getter;
+
+import java.util.*;
+
+@Getter
+public class LearningMaterial {
+
+ protected Collection types;
+ private String id;
+ private String text;
+
+
+ public LearningMaterial(String id, Collection types, String text){
+ this.id = id;
+ this.types = types;
+ this.text = text;
+ }
+ public LearningMaterial(String id, LearningResourceType type, String text){
+ this(id, new ArrayList<>(Arrays.asList(type)), text);
+ }
+
+ public LearningMaterial(LearningMaterial resource){
+ this(resource.getId(), resource.getTypes(), resource.getText());
+ }
+
+ public LearningMaterial(LearningResourceRecord record){
+ this(record.getId(), record.getResourceTypes(), record.getText());
+ }
+
+ public static Map deepCopyLearningMaterialMap(Map mapToCopy){
+ Map newMap = new HashMap<>();
+ for (Map.Entry entryToCopy : mapToCopy.entrySet()){
+ newMap.put(entryToCopy.getKey(), new LearningMaterial(entryToCopy.getValue()));
+ }
+ return newMap;
+ }
+
+}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/learningresource/LearningResource.java b/src/main/java/edu/ithaca/dragon/tecmap/learningresource/LearningResource.java
deleted file mode 100644
index 18f8405..0000000
--- a/src/main/java/edu/ithaca/dragon/tecmap/learningresource/LearningResource.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package edu.ithaca.dragon.tecmap.learningresource;
-
-import edu.ithaca.dragon.tecmap.io.record.LearningResourceRecord;
-
-import java.util.*;
-
-public class LearningResource {
-
- protected Collection types;
- private String id;
-
- public LearningResource(String id, Collection types){
- this.id = id;
- this.types = types;
- }
-
- public LearningResource(String id, LearningResourceType type){
- this(id, new ArrayList<>(Arrays.asList(type)));
- }
-
- public LearningResource(LearningResource material){
- this(material.getId(), material.types);
- }
-
- public LearningResource(LearningResourceRecord record){
- this(record.getLearningResourceId(), record.getResourceTypes());
- }
-
- public String getId() {
- return id;
- }
-
- public static Map deepCopyLearningResourceMap(Map mapToCopy){
- Map newMap = new HashMap<>();
- for (Map.Entry entryToCopy : mapToCopy.entrySet()){
- newMap.put(entryToCopy.getKey(), new LearningResource(entryToCopy.getValue()));
- }
- return newMap;
- }
-
-}
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/learningresource/ManualGradedResponse.java b/src/main/java/edu/ithaca/dragon/tecmap/learningresource/ManualGradedResponse.java
index 8489966..8553a97 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/learningresource/ManualGradedResponse.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/learningresource/ManualGradedResponse.java
@@ -10,9 +10,9 @@ public class ManualGradedResponse extends AssessmentItemResponse {
double maxPossibleScore;
double studentScore;
- public ManualGradedResponse(String learningObjectId, double max, double studentScore, String userId){
+ public ManualGradedResponse(String assessmentItemId, String text, double max, double studentScore, String userId){
- super(userId,learningObjectId,studentScore/max);
+ super(userId, assessmentItemId, text,studentScore/max);
this.maxPossibleScore = max;
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/legacy/ConceptKnowledgeCalculator.java b/src/main/java/edu/ithaca/dragon/tecmap/legacy/ConceptKnowledgeCalculator.java
index 03ef555..aaa6eb5 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/legacy/ConceptKnowledgeCalculator.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/legacy/ConceptKnowledgeCalculator.java
@@ -1,10 +1,9 @@
package edu.ithaca.dragon.tecmap.legacy;
+import com.opencsv.exceptions.CsvException;
import edu.ithaca.dragon.tecmap.Settings;
import edu.ithaca.dragon.tecmap.conceptgraph.*;
-import edu.ithaca.dragon.tecmap.io.reader.TecmapCSVReader;
-import edu.ithaca.dragon.tecmap.io.reader.ReaderTools;
-import edu.ithaca.dragon.tecmap.io.reader.SakaiReader;
+import edu.ithaca.dragon.tecmap.io.reader.*;
import edu.ithaca.dragon.tecmap.io.record.CohortConceptGraphsRecord;
import edu.ithaca.dragon.tecmap.io.record.ConceptGraphRecord;
import edu.ithaca.dragon.tecmap.io.record.LearningResourceRecord;
@@ -72,7 +71,7 @@ public ConceptKnowledgeCalculator(String structureFileName) throws IOException{
clearAndCreateStructureData(struct);
}
- public ConceptKnowledgeCalculator(String structureFilename, String resourceFilename, String assessmentFilename) throws IOException{
+ public ConceptKnowledgeCalculator(String structureFilename, String resourceFilename, String assessmentFilename) throws IOException, CsvException {
this();
List structure = new ArrayList<>();
@@ -87,7 +86,7 @@ public ConceptKnowledgeCalculator(String structureFilename, String resourceFilen
clearAndCreateCohortData(structure, resource, assessment);
}
- public ConceptKnowledgeCalculator(List structureFilenames, List resourceFilenames, List assessmentFilenames) throws IOException{
+ public ConceptKnowledgeCalculator(List structureFilenames, List resourceFilenames, List assessmentFilenames) throws IOException, CsvException {
this();
clearAndCreateCohortData(structureFilenames, resourceFilenames, assessmentFilenames);
}
@@ -135,7 +134,7 @@ public void updateStructureFile(String file) throws IOException {
@Override
- public void clearAndCreateCohortData(List structureFilename, List resourceFilename, List assessmentFilename) throws IOException {
+ public void clearAndCreateCohortData(List structureFilename, List resourceFilename, List assessmentFilename) throws IOException, CsvException {
structureGraph = null;
cohortConceptGraphs=null;
structureFiles.clear();
@@ -165,7 +164,10 @@ public void clearAndCreateCohortData(List structureFilename, List assessments = new ArrayList<>();
for (String aname: assessmentFiles){
- TecmapCSVReader tecmapCsvReader = new SakaiReader(aname);
+ List rows = CsvFileLibrary.parseRowsFromFile(aname);
+ List processors = new ArrayList<>();
+ processors.add(new CanvasConverter());
+ TecmapCSVReader tecmapCsvReader = new CanvasReader(rows, processors);
List temp = tecmapCsvReader.getManualGradedResponses();
assessments.addAll(temp);
}
@@ -513,10 +515,10 @@ public String csvToResource() throws Exception {
}
public static void csvToResource(List assessmentFiles, String destinationFilepath) throws Exception{
- //TODO: hardcoded to sakai csv, need to hold a list of CSVReaders, or the information about which kind of reader it is...
- List fullLoList = ReaderTools.assessmentItemsFromCSVList(2, assessmentFiles);
- List lolrList = LearningResourceRecord.createLearningResourceRecordsFromAssessmentItems(fullLoList);
- LearningResourceRecord.resourceRecordsToJSON(lolrList, destinationFilepath);
+ //TODO: hardcoded to canvas csv, need to hold a list of CSVReaders, or the information about which kind of reader it is...
+ List fullAIList = ReaderTools.assessmentItemsFromCSVList(assessmentFiles);
+ List lrrList = LearningResourceRecord.createLearningResourceRecordsFromAssessmentItems(fullAIList);
+ LearningResourceRecord.resourceRecordsToJSON(lrrList, destinationFilepath);
}
public static void conceptIdsToTextFile(Collection conceptIds, String destinationFilepath) throws Exception{
@@ -599,8 +601,11 @@ public boolean resourceIsValid(String name) throws IOException {
}
@Override
- public boolean assessmentIsValid(String name) throws IOException {
- TecmapCSVReader tecmapCsvReader = new SakaiReader(name);
+ public boolean assessmentIsValid(String name) throws IOException, CsvException {
+ List rows = CsvFileLibrary.parseRowsFromFile(name);
+ List processors = new ArrayList<>();
+ processors.add(new CanvasConverter());
+ TecmapCSVReader tecmapCsvReader = new CanvasReader(rows, processors);
if (tecmapCsvReader.getManualGradedResponses().size()>0){
return true;
}else{
diff --git a/src/main/java/edu/ithaca/dragon/tecmap/legacy/ConceptKnowledgeCalculatorAPI.java b/src/main/java/edu/ithaca/dragon/tecmap/legacy/ConceptKnowledgeCalculatorAPI.java
index 7627aa3..3faa2c7 100644
--- a/src/main/java/edu/ithaca/dragon/tecmap/legacy/ConceptKnowledgeCalculatorAPI.java
+++ b/src/main/java/edu/ithaca/dragon/tecmap/legacy/ConceptKnowledgeCalculatorAPI.java
@@ -1,5 +1,6 @@
package edu.ithaca.dragon.tecmap.legacy;
+import com.opencsv.exceptions.CsvException;
import edu.ithaca.dragon.tecmap.conceptgraph.CohortConceptGraphs;
import edu.ithaca.dragon.tecmap.conceptgraph.ConceptGraph;
import edu.ithaca.dragon.tecmap.suggester.GroupSuggester.Group;
@@ -32,7 +33,7 @@ public interface ConceptKnowledgeCalculatorAPI {
* @param resourceFilename a json file listing the resources and their links to the concepts
* @param assessmentFilename a csv file containing rows of students and columns labeled with resourceIds
*/
- void clearAndCreateCohortData(List