[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Instance.java, 1.14, 1.15 Space.java
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2010-05-07 13:36:10
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv4772/src/net/sourceforge/bprocessor/model Modified Files: Instance.java Space.java Project.java Log Message: Index: Instance.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Instance.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Instance.java 12 Feb 2010 14:36:40 -0000 1.14 --- Instance.java 7 May 2010 13:35:58 -0000 1.15 *************** *** 28,31 **** --- 28,36 ---- /** + * Storage + */ + private Object storage; + + /** * */ *************** *** 71,74 **** --- 76,93 ---- /** + * @return Object + */ + public Object getStorage() { + return storage; + } + + /** + * @param value Object + */ + public void setStorage(Object value) { + storage = value; + } + + /** * @param system CoordinateSystem */ Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.250 retrieving revision 1.251 diff -C2 -d -r1.250 -r1.251 *** Space.java 22 Apr 2010 08:13:47 -0000 1.250 --- Space.java 7 May 2010 13:35:58 -0000 1.251 *************** *** 87,92 **** --- 87,94 ---- } out.println(); + } } + out.println("#"); } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.189 retrieving revision 1.190 diff -C2 -d -r1.189 -r1.190 *** Project.java 26 Apr 2010 09:30:05 -0000 1.189 --- Project.java 7 May 2010 13:35:58 -0000 1.190 *************** *** 23,27 **** --- 23,30 ---- import java.net.URL; import java.net.URLConnection; + import java.text.DateFormat; import java.text.DecimalFormat; + import java.text.ParseException; + import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; *************** *** 50,53 **** --- 53,57 ---- import net.sourceforge.bprocessor.model.brunata.io.DocumentParser; import net.sourceforge.bprocessor.model.sense.SensorItem; + import net.sourceforge.bprocessor.model.sense.SensorStorage; import net.sourceforge.bprocessor.model.xml.Bmodel; *************** *** 86,89 **** --- 90,96 ---- private static boolean brunata; + private static String initialDate = "2010.04.01 00:00:00"; + private static boolean initialized; + private static long stamp; private Tesselator tesselator; *************** *** 1156,1160 **** } else if (a.getName().equals("Brunata Server")) { brunata = ((Boolean) a.getValue()).booleanValue(); ! } } changed(this); --- 1163,1169 ---- } else if (a.getName().equals("Brunata Server")) { brunata = ((Boolean) a.getValue()).booleanValue(); ! } else if (a.getName().equals("Initial Date")) { ! setInitialDate((String)a.getValue()); ! } } changed(this); *************** *** 1175,1178 **** --- 1184,1188 ---- if (BRUN) { res.add(new Attribute("Brunata Server", Boolean.valueOf(brunata))); + res.add(new Attribute("Initial Date", initialDate)); } res.add(new Attribute("Script", script)); *************** *** 1815,1818 **** --- 1825,1839 ---- } + private static List<Instance> getSensors() { + List<Instance> result = new LinkedList(); + List<Instance> instances = Project.getInstance().world().collectInstances(); + for (Instance current : instances) { + Space space = current.getProto(); + if (space.getName().equals("Sensor")) { + result.add(current); + } + } + return result; + } private List<Space> constructs(Collection<Space> spaces) { *************** *** 1869,1875 **** --- 1890,1899 ---- File mtlfile = new File(file, "materials.mtl"); exportMtl(materials, new FileOutputStream(mtlfile)); + int count = 1; List<String> names = new LinkedList(); Set<String> mark = new HashSet(); + Map<String, Space> map = new HashMap(); + for (Space current : constructs) { *************** *** 1880,1891 **** --- 1904,1923 ---- } else if (mark.contains(name)) { name = "construct-" + count++; + } else { + name = "construct-" + count++; } mark.add(name); names.add(name); + map.put(name, current); File objfile = new File(file, name + ".obj"); OutputStream out = new FileOutputStream(objfile); PrintStream printer = new PrintStream(out); printer.println("mtllib materials.mtl"); + Material material = current.getMaterial(); + if (material == null) { + material = Defaults.getConstructionMaterial(); + } + printer.println("usemtl " + material.getName()); exportObj(current, out); } *************** *** 1895,1900 **** PrintStream printer = new PrintStream(new FileOutputStream(scnfile)); printer.println("<Scene>"); for (String current : names) { ! printer.println(" <ObjFile name=\"" + current + ".obj\"/>"); } printer.println("</Scene>"); --- 1927,1954 ---- PrintStream printer = new PrintStream(new FileOutputStream(scnfile)); printer.println("<Scene>"); + + for (Material current : getMaterials()) { + current.exportXml(printer); + } + + for (Camera current : getCameras()) { + current.exportXml(printer); + } + + for (String current : names) { ! Space construct = map.get(current); ! ! Material material = construct.getMaterial(); ! if (material == null) { ! material = Defaults.getConstructionMaterial(); ! } ! String header = "<Object" ! + " name=\"" + current + "\"" ! + " material=\"" + material.getName() + "\"" ! + " filename=\"" + current + ".obj" + "\"" ! + "/>"; ! ! printer.println(" " + header); } printer.println("</Scene>"); *************** *** 2095,2099 **** --- 2149,2200 ---- } + private void setInitialDate(String value) { + initialDate = value; + initialized = false; + if (brunata) { + fetch(); + } + } + private void fetch() { + System.out.println("fetching..."); + List<Instance> sensors = getSensors(); + if (initialized) { + // + } else { + for (Instance current : sensors) { + String value = (String) current.getParameters().get("Intern ID"); + System.out.println(value); + long id = Long.valueOf(value); + SensorStorage storage = new SensorStorage(id); + current.setStorage(storage); + } + DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); + try { + Date date = format.parse(initialDate); + stamp = date.getTime(); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + for (Instance current : sensors) { + SensorStorage storage = (SensorStorage) current.getStorage(); + if (storage != null) { + long id = storage.getId(); + try { + List<SensorItem> items = process(id, new Date(stamp)); + storage.update(items); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + stamp = System.currentTimeMillis(); + initialized = true; + Project.getInstance().changed(Project.getInstance()); + } + } + + private void fetch1() { try { List<SensorItem> items1 = process(2501858); *************** *** 2134,2137 **** --- 2235,2240 ---- } + + /** * *************** *** 2158,2163 **** --- 2261,2286 ---- } + private static URL address(long id, Date from) throws Exception { + String www = "https://ext.brunata.com/ws-webmon/v1/da/"; + String login = "040985:b35c52662aee64d6b12faa2a2eb7013a/"; + String what = "meters/"; + String type = ":(DEWPOINT,HUMIDITY,TEMPERATURE).xml"; + String parameter = "?period=" + from.getTime(); + String address = www + login + what + id + type + parameter; + return new URL(address); + } + + private List<SensorItem> process(long id) throws Exception { URL url = address(id); + return process(id, url); + } + + private List<SensorItem> process(long id, Date from) throws Exception { + URL url = address(id, from); + return process(id, url); + } + + private List<SensorItem> process(long id, URL url) throws Exception { XMLDocument document = fetch(url); BPersistence persistence = new BPersistence(); |