| 1 | /////////////////////////////////////////////////////// |
|---|
| 2 | // XML File Loading |
|---|
| 3 | /////////////////////////////////////////////////////// |
|---|
| 4 | String xmlFiles[]; |
|---|
| 5 | void getXMLlist() { |
|---|
| 6 | xmlFiles = new String[MAXXMLFILES] ; |
|---|
| 7 | File file = new File(xmlFilesFolder); |
|---|
| 8 | xmlFiles = file.list(); |
|---|
| 9 | nXmlFiles = xmlFiles.length ; |
|---|
| 10 | print("N XML Files : "+nXmlFiles+"\n") ; |
|---|
| 11 | for (int i = 0; i < xmlFiles.length; i++) { |
|---|
| 12 | //print("LISTING : "+xmlFiles[i]+"\n") ; |
|---|
| 13 | int timp = getTimeStampFromFileName(xmlFiles[i]) ; |
|---|
| 14 | //print("tmpsp : "+timp+"\n") ; |
|---|
| 15 | if(timp<minTimeStamp) minTimeStamp = timp ; |
|---|
| 16 | if(timp>maxTimeStamp) maxTimeStamp = timp ; |
|---|
| 17 | } |
|---|
| 18 | print("MAXMIN XML Files : "+minTimeStamp+" "+maxTimeStamp+"\n") ; |
|---|
| 19 | } |
|---|
| 20 | int getTimeStampFromFileName(String inStr) { |
|---|
| 21 | String[] dec1 = split(inStr, '_'); |
|---|
| 22 | String[] dec2 = split(dec1[1], '.'); |
|---|
| 23 | int timp = int(dec2[0]) ; |
|---|
| 24 | return timp ; |
|---|
| 25 | } |
|---|
| 26 | void loadXMLData() { |
|---|
| 27 | |
|---|
| 28 | boolean firstLoad = false ; |
|---|
| 29 | if(nClients==0) firstLoad = true ; |
|---|
| 30 | |
|---|
| 31 | try{ |
|---|
| 32 | String xmlPath ; |
|---|
| 33 | |
|---|
| 34 | if(loadFromXMLlist) { // Loading from list |
|---|
| 35 | currXmlListN++ ; |
|---|
| 36 | int currN = currXmlListN%nXmlFiles ; |
|---|
| 37 | xmlPath = "/xml/"+xmlFiles[currN] ; |
|---|
| 38 | currTimeStamp = getTimeStampFromFileName( xmlFiles[currN] ) ; |
|---|
| 39 | //print("Loading XML from LIST : "+currTimeStamp+" "+currN+"\n") ; |
|---|
| 40 | } |
|---|
| 41 | else { // Loading from live/sample file |
|---|
| 42 | if(loadXmlFromSample) xmlPath = xmlFileAddressSample ; |
|---|
| 43 | else xmlPath = xmlFileAddressLive ; |
|---|
| 44 | print("Loading XML from : "+xmlPath+"\n") ; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | XMLElement xml = new XMLElement(this, xmlPath) ; |
|---|
| 48 | //data.printElementTree(" "); |
|---|
| 49 | // 0 is Version |
|---|
| 50 | XMLElement Config = xml.getChild(1); // config |
|---|
| 51 | |
|---|
| 52 | String lastChecked = Config.getChild(0).getContent() ; |
|---|
| 53 | |
|---|
| 54 | if(!lastChecked.equals(lastXmlDate) || firstLoad || loadXmlFromSample) { //// new xml file !! --> load |
|---|
| 55 | lastXmlDate = lastChecked ; |
|---|
| 56 | |
|---|
| 57 | XMLElement Links = Config.getChild(2); // links |
|---|
| 58 | // 2 is Tags |
|---|
| 59 | XMLElement Users = xml.getChild(2); // users |
|---|
| 60 | |
|---|
| 61 | int newN = int( Config.getChild(1).getContent() ) ; |
|---|
| 62 | //print("XML: Importing ("+newN +") Users ...\n") ; |
|---|
| 63 | ///// Vars |
|---|
| 64 | String nam,desc,author,location,logi,ipAdr ; |
|---|
| 65 | String fDate,lDate ; |
|---|
| 66 | float sReach, sAct, sSociab, sWeig ; //activity, reachability |
|---|
| 67 | String inV,inA,inD,outV,outA,outD,newVip,newAip ; |
|---|
| 68 | |
|---|
| 69 | /////////// Getting new state |
|---|
| 70 | String dStat = Links.getChild(0).getContent() ; |
|---|
| 71 | String aStat = Links.getChild(1).getContent() ; |
|---|
| 72 | String vStat = Links.getChild(2).getContent() ; |
|---|
| 73 | |
|---|
| 74 | running = false ; |
|---|
| 75 | |
|---|
| 76 | String[] newDates ; |
|---|
| 77 | newDates = new String[newN] ; |
|---|
| 78 | |
|---|
| 79 | for(int i = 0 ; i < newN ; i++) { |
|---|
| 80 | XMLElement User = Users.getChild(i); |
|---|
| 81 | logi = User.getAttribute("login") ; |
|---|
| 82 | |
|---|
| 83 | //print("XML: Importing : "+logi+"\n") ; |
|---|
| 84 | |
|---|
| 85 | fDate = User.getChild(0).getContent() ; |
|---|
| 86 | lDate = User.getChild(1).getContent() ; |
|---|
| 87 | nam = User.getChild(2).getContent() ; |
|---|
| 88 | author = User.getChild(3).getContent() ; |
|---|
| 89 | desc = User.getChild(4).getContent() ; |
|---|
| 90 | location = User.getChild(5).getContent() ; |
|---|
| 91 | ipAdr = User.getChild(6).getContent() ; |
|---|
| 92 | |
|---|
| 93 | //// Updating date stats : |
|---|
| 94 | newDates[i] = lDate ; |
|---|
| 95 | |
|---|
| 96 | XMLElement inChild = User.getChild(7) ; // IN |
|---|
| 97 | inD = inChild.getChild(0).getContent() ; |
|---|
| 98 | inA = inChild.getChild(1).getContent() ; |
|---|
| 99 | inV = inChild.getChild(2).getContent() ; |
|---|
| 100 | |
|---|
| 101 | XMLElement outChild = User.getChild(8) ; // OUT |
|---|
| 102 | outD = outChild.getChild(0).getContent() ; |
|---|
| 103 | outA = outChild.getChild(1).getContent() ; |
|---|
| 104 | outV = outChild.getChild(2).getContent() ; |
|---|
| 105 | newVip = outChild.getChild(3).getContent() ; |
|---|
| 106 | newAip = outChild.getChild(4).getContent() ; |
|---|
| 107 | |
|---|
| 108 | XMLElement statChild = User.getChild(9) ; // STATS (recuperation) |
|---|
| 109 | sReach = float( statChild.getChild(0).getContent() ) ; |
|---|
| 110 | sAct = float( statChild.getChild(1).getContent() ) ; |
|---|
| 111 | sSociab = float( statChild.getChild(2).getContent() ) ; |
|---|
| 112 | sWeig = float( statChild.getChild(3).getContent() ) ; |
|---|
| 113 | |
|---|
| 114 | Aspiration in[] = { |
|---|
| 115 | new Aspiration(0,inD),new Aspiration(1,inA),new Aspiration(2,inV) } |
|---|
| 116 | ; |
|---|
| 117 | Determinant out[] = { |
|---|
| 118 | new Determinant(0,outD,true),new Determinant(1,outA,true),new Determinant(2,outV,true) } |
|---|
| 119 | ; |
|---|
| 120 | |
|---|
| 121 | Client toUpd ; |
|---|
| 122 | if(i<nClients) { // already here, just updating data |
|---|
| 123 | toUpd = getClient(i) ; |
|---|
| 124 | toUpd.name = nam ; |
|---|
| 125 | toUpd.descr = desc ; |
|---|
| 126 | toUpd.lastDate = lDate ; |
|---|
| 127 | toUpd.setIP(ipAdr) ; |
|---|
| 128 | toUpd.setOutAudioStream(newAip) ; |
|---|
| 129 | toUpd.setOutVideoStream(newVip) ; |
|---|
| 130 | toUpd.out[0].setString(outD,false); |
|---|
| 131 | toUpd.out[1].setString(outA,false); |
|---|
| 132 | toUpd.out[2].setString(outV,false); |
|---|
| 133 | toUpd.in[0].setString(inD); |
|---|
| 134 | toUpd.in[1].setString(inA); |
|---|
| 135 | toUpd.in[2].setString(inV); |
|---|
| 136 | } |
|---|
| 137 | else { |
|---|
| 138 | toUpd = new Client(i,logi,nam,desc,in,out) ; |
|---|
| 139 | toUpd.setIP( ipAdr ) ; |
|---|
| 140 | toUpd.setOutAudioStream(newAip) ; |
|---|
| 141 | toUpd.setOutVideoStream(newVip) ; |
|---|
| 142 | toUpd.lastDate = lDate ; |
|---|
| 143 | toUpd.firstDate = fDate ; |
|---|
| 144 | safelyAddNewClient( toUpd ) ; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | // Client Stats and last infos |
|---|
| 148 | toUpd.author = author ; |
|---|
| 149 | toUpd.location = location ; |
|---|
| 150 | toUpd.sReachability = sReach ; |
|---|
| 151 | toUpd.sActivity = sAct ; |
|---|
| 152 | toUpd.sSociability = sSociab ; |
|---|
| 153 | toUpd.sWeight = sWeig ; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | ////////////// Updating date Stats, assuming at least 1 user |
|---|
| 157 | String[] sortedDates = sort(newDates) ; |
|---|
| 158 | clientsOldestDate = int(sortedDates[0]) ; |
|---|
| 159 | clientsNewestDate = int(sortedDates[newN-1]) ; |
|---|
| 160 | |
|---|
| 161 | ////////////// Updating State with nClients2 |
|---|
| 162 | drawnState = new State(dStat,aStat,vStat) ; |
|---|
| 163 | //drawnState.dConfig[i] = (dStat.charAt(i)=='1') ; |
|---|
| 164 | //drawnState.aConfig[i] = (aStat.charAt(i)=='1') ; |
|---|
| 165 | //drawnState.vConfig[i] = (vStat.charAt(i)=='1') ; |
|---|
| 166 | |
|---|
| 167 | running = true ; |
|---|
| 168 | |
|---|
| 169 | if(firstLoad) basculeToRandomPosition() ; |
|---|
| 170 | } |
|---|
| 171 | else print("Not loading because you have already the last XML version\n") ; |
|---|
| 172 | } |
|---|
| 173 | catch(Exception e){ |
|---|
| 174 | print("Exception Problem while loading XML file: "+e+"\n") ; |
|---|
| 175 | } |
|---|
| 176 | } |
|---|
| 177 | //////////////////////////////////////////////////////////// |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|