summaryrefslogtreecommitdiff
path: root/parsecalldata.pde
blob: 4247041c44fa06f036dfe26bd639f7417b761bfc (plain)
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
//BT IRELAND MTM,Destination CID Name,VIA,Calls,MINS,ALOC,% User,ASR,NER 02
boolean DEBUG=false;

class country {
  String name;
  float calls,mins;
  RShape outline;
  country(String n,float c,float m,RShape shp){
    name=n;
    calls=c;
    mins=m;
    outline=shp;
  }
  void addnetwork(float c,float m) {
    calls+=c;
    mins+=m;
  }
  void printOut() {
    println(name+" "+calls+" "+mins);
  }
  RPoint getpoint(int tries){
      RPoint tl=outline.getTopLeft();
      RPoint br=outline.getBottomRight();
      RPoint np= new RPoint(0,0);
      int searching =1;
      while (searching>0&&searching<tries) {
        np=new RPoint(random(tl.x,br.x),random(tl.y,br.y));
        if(outline.contains(np)) searching=0;
        if (DEBUG) println(name+"; try  "+searching+": "+np.x+","+np.y+" bounds: "+tl.x+","+tl.y+" - "+br.x+","+br.y+": "+(searching>0));
        if (searching==10||searching==100||searching==1000||searching==10000||searching==100000) {
          println(name+"; try  "+searching+": MISS at "+np.x+","+np.y+" bounds: "+tl.x+","+tl.y+" - "+br.x+","+br.y);
        }
      }
      if (searching==0) return np;
      else return new RPoint(0,0);
  }
}

class calldata {
  
  Vector<country> countries = new Vector<country>();
  HashMap<String, Integer> outlines = new HashMap<String, Integer>();
  calldata(String[][] data,RShape shp) {
    
    for (int i=0;i<shp.children.length;i++) {
      outlines.put(shp.children[i].name.substring(0, 3),i);
    }
 
    println("parsing "+data.length+" entries");
    //detect number of countries
    int num=0;
    if (outlines.containsKey(data[0][1].substring(0, 3))) {
      countries.add(new country(data[0][1],0,0,shp.children[outlines.get(data[0][1].substring(0, 3))]));
    }
  
    for (int i=0; i < data.length; i++) { 
      if (data[i][1].substring(0,3).equals(countries.lastElement().name.substring(0, 3))) {
        countries.lastElement().addnetwork(Float.valueOf(data[i][3].trim()).floatValue(),Float.valueOf(data[i][4].trim()).floatValue());
      }
      
      else {
        if (outlines.containsKey(data[i][1].substring(0, 3))) {
          countries.add(new country(data[i][1],Float.valueOf(data[i][3].trim()).floatValue(),Float.valueOf(data[i][4].trim()).floatValue(),shp.children[outlines.get(data[i][1].substring(0, 3))]));
        }
      }      
    }
   for (int i=0; i < countries.size(); i++) { 
      countries.get(i).printOut();
   }

  }
  country getcountry(int w) {
    return countries.get(w);
  }
}