summaryrefslogtreecommitdiff
path: root/parsecalldata.pde
diff options
context:
space:
mode:
authorgit@eclectronics.org <git@eclectronics.org@eclectronics.org>2012-02-19 23:38:58 +0000
committergit@eclectronics.org <git@eclectronics.org@eclectronics.org>2012-02-19 23:38:58 +0000
commit6bc8d43cc205e00485c865de4b04d93c4270ff22 (patch)
treef913d9b1201117609c9eadb35866318ff65eacc4 /parsecalldata.pde
parentd6ffb40609d3fedcb2f4cae9ab64ebc7ac7f6521 (diff)
perspective circles + sampling working
Diffstat (limited to 'parsecalldata.pde')
-rw-r--r--parsecalldata.pde138
1 files changed, 94 insertions, 44 deletions
diff --git a/parsecalldata.pde b/parsecalldata.pde
index e3688c6..ecc1a77 100644
--- a/parsecalldata.pde
+++ b/parsecalldata.pde
@@ -10,22 +10,37 @@ import proxml.*;
// use proxml manually
//
+
class country{
String name;
- float calls,mins;
+ float calls,mins,aloc,user,asr,ner;
+ int networks;
transient RShape outline;
- country() {
- super();
- }
- country(String n,float c,float m,RShape shp){
+ country(String n,float c,float m,float al,float u,float as,float ne,RShape shp){
name=n;
calls=c;
mins=m;
+ aloc=al;
+ user=u;
+ asr=as;
+ ner=ne;
outline=shp;
+ networks=1;
}
- void addnetwork(float c,float m) {
+ void addnetwork(float c,float m,float al,float u,float as,float ne) {
calls+=c;
mins+=m;
+ aloc+=al;
+ user+=u;
+ asr+=as;
+ ner+=ne;
+ networks++;
+ }
+ void getavgs() {
+ aloc/=networks;
+ user/=networks;
+ asr/=networks;
+ ner/=networks;
}
void printOut() {
println(name+" "+calls+" "+mins);
@@ -46,13 +61,14 @@ class country{
if (searching==0) return np;
else return new RPoint(0,0);
}
- RPoint getcentre() {
- RPoint tl=outline.getTopLeft();
- RPoint br=outline.getBottomRight();
- return new RPoint((tl.x+br.x)/2,(tl.y+br.y)/2);
- }
+ RPoint getcentre(){
+ RPoint tl=outline.getTopLeft();
+ RPoint br=outline.getBottomRight();
+ return new RPoint((tl.x+br.x)*0.5,(tl.y+br.y)*0.5);
+}
}
+
class weightedpixel {
float bright;
RPoint pt;
@@ -61,6 +77,9 @@ class weightedpixel {
pt=_p;
bright=_b;
}
+ RPoint randompt(float r) {
+ return new RPoint(pt.x+random(r),pt.y+random(r));
+ }
}
class bitmapcountry extends country {
@@ -77,13 +96,13 @@ class bitmapcountry extends country {
//sample brightness, keep running total and store normalised weighted index for quick searching
float xo,xs,yo,ys;
+ float btotal,bavg,bmin,bmax;
Vector<weightedpixel> points = new Vector<weightedpixel>();
- bitmapcountry(){super();}
- bitmapcountry(String n,float c,float m,RShape shp) {
- super(n,c,m,shp);
+ bitmapcountry(String n,float c,float m,float al,float u,float as,float ne,RShape shp) {
+ super(n,c,m,al,u,as,ne,shp);
}
void analyse(float _xo,float _xs,float _yo,float _ys) {
- int step=10; //speedup
+ int step=2; //speedup
xo=_xo;
xs=_xs;
yo=_yo;
@@ -93,30 +112,32 @@ class bitmapcountry extends country {
RPoint br=outline.getBottomRight();
RPoint tlp=normpix(tl);
RPoint brp=normpix(br);
- float pixstep=xs/lightmap.width;
- float totalbright=0;
- float bmin=255;
- float bmax=0;
- println("searching "+tl.x+","+tl.y+" -> "+(tl.x+(pixstep*(brp.x-tlp.x)))+","+(tl.y+(pixstep*(brp.y-tlp.y))));
+ float xstep=xs/lightmap.width;
+ float ystep=ys/lightmap.height;
+ btotal=0;
+ bmin=255;
+ bmax=0;
+ println("searching "+tl.x+","+tl.y+" -> "+(tl.x+(xstep*(brp.x-tlp.x)))+","+(tl.y+(ystep*(brp.y-tlp.y)))+" by "+xstep+","+ystep);
for (int i=0;i<brp.x-tlp.x;i+=step) {
for (int j=0;j<brp.y-tlp.y;j+=step) {
- RPoint pn=new RPoint(tl.x+(i*pixstep),tl.y+(j*pixstep));
+ RPoint pn=new RPoint(tl.x+(i*xstep),tl.y+(j*ystep));
if(outline.contains(pn)) {
- float bn=brightness(lightmap.get((int)brp.x+i,(int)brp.y+j))+1;//gives a 0.5% weighting to blank pixels
+ float bn=brightness(lightmap.get((int)tlp.x+i,(int)tlp.y+j))+1;//gives a 0.4% weighting to blank pixels
points.add(new weightedpixel(pn,bn));
- totalbright +=bn;
+ btotal +=bn;
if (bn>bmax) bmax=bn;
if (bn<bmin) bmin=bn;
}
}
}
float runbright=0;
- float bfactor=1.0/totalbright;
+ float bfactor=1.0/btotal;
for (int i=0;i<points.size();i++) {
runbright+=points.get(i).bright*bfactor;
points.get(i).index=runbright;
}
- if (DEBUG) println(name+"; bounds: "+tl.x+","+tl.y+" : "+br.x+","+br.y+" - "+points.size()+" pixels, "+bmin+"-"+bmax+" avg: "+(totalbright/points.size()));
+ bavg=(btotal/points.size());
+ if (DEBUG) println(name+"; bounds: "+tl.x+","+tl.y+" : "+br.x+","+br.y+" - "+points.size()+" pixels, "+bmin+"-"+bmax+" avg: "+bavg);
}
RPoint normalise(RPoint p) {
@@ -132,22 +153,31 @@ class bitmapcountry extends country {
return new RPoint(px,py);
}
RPoint getpoint(){
- float index=random(1.0);
+ float index=random(0.99999);
int i=0;
- while (points.get(i).index<index&&i<points.size()) {
+ while (points.get(i).index<index) {
i++;
}
return new RPoint(points.get(i).pt.x+random(1),points.get(i).pt.y+random(1));
}
+ weightedpixel getpixel(){
+ float index=random(0.99999);
+ int i=0;
+ while (points.get(i).index<index) {
+ i++;
+ }
+ return points.get(i);
+ }
}
class calldata {
+ float start;
Vector<bitmapcountry> countries = new Vector<bitmapcountry>();
HashMap<String, Integer> outlines = new HashMap<String, Integer>();
proxml.XMLElement xmlcountries;
XMLInOut xmlInOut;
PApplet pApplet;
- boolean loaded;
+ boolean loaded;
country getcountry(int w) {
return countries.get(w);
@@ -165,26 +195,30 @@ class calldata {
country = xmlcountries.getChild(i);
String name=country.getAttribute("name");
if (outlines.containsKey(name.substring(0, 3))) {
- bitmapcountry c=new bitmapcountry(name,(int)country.getFloatAttribute("calls"),(int)country.getFloatAttribute("mins"),shp.children[outlines.get(name.substring(0, 3))]);
+ bitmapcountry c=new bitmapcountry(name,country.getFloatAttribute("calls"),country.getFloatAttribute("mins"),country.getFloatAttribute("aloc"),country.getFloatAttribute("user"),country.getFloatAttribute("asr"),country.getFloatAttribute("ner"),shp.children[outlines.get(name.substring(0, 3))]);
for(int j = 0; j < country.countChildren();j++){
pt = country.getChild(j);
weightedpixel p=new weightedpixel(new RPoint(pt.getFloatAttribute("x"),pt.getFloatAttribute("y")),pt.getFloatAttribute("b"));
p.index=pt.getFloatAttribute("i");
c.points.add(p);
}
+ c.btotal=country.getFloatAttribute("btotal");
+ c.bmax=country.getFloatAttribute("bmax");
+ c.bmin=country.getFloatAttribute("bmin");
+ c.bavg=c.btotal/c.points.size();
pts+=country.countChildren();
countries.add(c);
}
}
- println("loaded "+countries.size()+" countries, "+pts+" data points");
- loaded=true;
+ println("loaded "+countries.size()+" countries, "+pts+" data points in "+((millis()-start)*.001)+"secs");
+ loaded=true;
}
calldata(String[][] data,RShape shp,String filename,PApplet _pApplet) {
+ start=millis();
boolean parsedata=true;
pApplet=_pApplet;
loaded=false;
-
/*
try { //to deserialise
File file = new File("countries.dat");
@@ -208,7 +242,7 @@ class calldata {
xmlInOut = new XMLInOut(pApplet);
try{
- xmlInOut.loadElement(filename);
+ xmlInOut.loadElement(filename);
}catch(Exception e){
//if the xml file could not be loaded it has to be created
proxml.XMLElement xmlcountries = new proxml.XMLElement("xmlcountries");
@@ -217,25 +251,40 @@ class calldata {
//detect number of countries
int num=0;
if (outlines.containsKey(data[0][1].substring(0, 3))) {
- countries.add(new bitmapcountry(data[0][1],0.0,0.0,shp.children[outlines.get(data[0][1].substring(0, 3))]));
+ countries.add(new bitmapcountry(data[0][1],Float.valueOf(data[0][3].trim()),Float.valueOf(data[0][4].trim()),Float.valueOf(data[0][5].trim()),Float.valueOf(data[0][6].trim()),Float.valueOf(data[0][7].trim()),Float.valueOf(data[0][8].trim()),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());
- }
+ if (data[i][1].substring(0,3).equals(countries.lastElement().name.substring(0, 3))) {
+ //2x try-catch to catch empty fields in csv. fix data with search-replace ,, to ,0, and ,/n to ,0/n
+ try {
+ countries.lastElement().addnetwork(Float.valueOf(data[i][3].trim()),Float.valueOf(data[i][4].trim()),Float.valueOf(data[i][5].trim()),Float.valueOf(data[i][6].trim()),Float.valueOf(data[i][7].trim()),Float.valueOf(data[i][8].trim()));
+ }catch(Exception ee){
+ println("empty string in "+data[i][0]+","+data[i][1]+","+data[i][2]+","+data[i][3]+","+data[i][4]+","+data[i][5]+","+data[i][6]+","+data[i][7]+","+data[i][8]+",");
+ }
+
+ }
else {
if (outlines.containsKey(data[i][1].substring(0, 3))) {
- countries.add(new bitmapcountry(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))]));
+ countries.add(new bitmapcountry(data[i][1],Float.valueOf(data[i][3].trim()),Float.valueOf(data[i][4].trim()),Float.valueOf(data[i][5].trim()),Float.valueOf(data[i][6].trim()),Float.valueOf(data[i][7].trim()),Float.valueOf(data[i][8].trim()),shp.children[outlines.get(data[i][1].substring(0, 3))]));
}
}
}
- for (int i=0; i < countries.size(); i++) {
- //if (DEBUG) countries.get(i).printOut();
- countries.get(i).analyse(18.279,746.302,129.314,374.293);
+
+ for (int i=0; i < countries.size(); i++) {
+ //if (DEBUG) countries.get(i).printOut();
+ countries.get(i).getavgs();
+ countries.get(i).analyse(18.279,746.302,109,374.293);
proxml.XMLElement country = new proxml.XMLElement("country");
country.addAttribute("name",countries.get(i).name);
country.addAttribute("calls",countries.get(i).calls);
country.addAttribute("mins",countries.get(i).mins);
+ country.addAttribute("aloc",countries.get(i).aloc);
+ country.addAttribute("user",countries.get(i).user);
+ country.addAttribute("asr",countries.get(i).asr);
+ country.addAttribute("ner",countries.get(i).ner);
+ country.addAttribute("btotal",countries.get(i).btotal);
+ country.addAttribute("bmin",countries.get(i).bmin);
+ country.addAttribute("bmax",countries.get(i).bmax);
for (int j=0; j < countries.get(i).points.size(); j++) {
proxml.XMLElement pt = new proxml.XMLElement("pt");
pt.addAttribute("b",countries.get(i).points.get(j).bright);
@@ -245,10 +294,11 @@ class calldata {
country.addChild(pt);
}
xmlcountries.addChild(country);
- }
+ }
xmlInOut.saveElement(xmlcountries,filename);
- loaded=true;
- }
+ println("generated "+filename+": "+countries.size()+" countries in "+((millis()-start)*.001)+"secs");
+ loaded=true;
+ }
}
}