diff options
| -rw-r--r-- | csvloader.pde | 35 | ||||
| -rw-r--r-- | parsecalldata.pde | 39 |
2 files changed, 74 insertions, 0 deletions
diff --git a/csvloader.pde b/csvloader.pde new file mode 100644 index 0000000..c8ba771 --- /dev/null +++ b/csvloader.pde @@ -0,0 +1,35 @@ +//for importing csv files into a 2d array +//thanks to che-wei wang + +class csvloader { + + String [][] data; + + csvloader(String file) { + + String lines[] = loadStrings(file); + int csvWidth=0; + + //calculate max width of csv file + for (int i=0; i < lines.length; i++) { + String [] chars=split(lines[i],','); + if (chars.length>csvWidth){ + csvWidth=chars.length; + } + } + + //create csv array based on # of rows and columns in csv file + data = new String [lines.length][csvWidth]; + + //parse values into 2d array + for (int i=0; i < lines.length; i++) { + String [] temp = new String [lines.length]; + temp= split(lines[i], ','); + for (int j=0; j < temp.length; j++){ + data[i][j]=temp[j]; + } + } + println("loaded "+file); + } +} + diff --git a/parsecalldata.pde b/parsecalldata.pde new file mode 100644 index 0000000..0406194 --- /dev/null +++ b/parsecalldata.pde @@ -0,0 +1,39 @@ +//BT IRELAND MTM,Destination CID Name,VIA,Calls,MINS,ALOC,% User,ASR,NER 02 + +class country { + String name; + float calls,mins; + country(String n,String c,String m){ + name=n; + calls=Float.valueOf(c.trim()).floatValue(); + mins=Float.valueOf(m.trim()).floatValue(); + } + void addnetwork(String c,String m) { + calls+=Float.valueOf(c.trim()).floatValue(); + mins+=Float.valueOf(m.trim()).floatValue(); + } + void printOut() { + println(name+" "+calls+" "+mins); + } +} + +class calldata { + + Vector<country> countries = new Vector<country>(); + calldata(String[][] data) { + println("parsing "+data.length+" entries"); + //detect number of countries + int num=0; + countries.add(new country(data[0][1],"0","0")); + for (int i=0; i < data.length; i++) { + if (data[i][1].substring(0, 2).equals(countries.lastElement().name.substring(0, 2))) { + countries.lastElement().addnetwork(data[i][3],data[i][4]); + } + else { + countries.lastElement().printOut(); + countries.add(new country(data[i][1],data[i][3],data[i][4])); + } + } + } + +} |
