[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Item.java, 1.3, 1.4 Command.java, 1.
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv28029/src/net/sourceforge/bprocessor/model Modified Files: Item.java Command.java Project.java Component.java ParameterBlock.java Attribute.java Log Message: Index: Attribute.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Attribute.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Attribute.java 3 Sep 2009 08:18:12 -0000 1.27 --- Attribute.java 12 Feb 2010 11:44:28 -0000 1.28 *************** *** 198,200 **** --- 198,208 ---- } } + + /** + * + * @return copy of this attribute + */ + public Attribute copy() { + return new Attribute(name, value); + } } Index: Component.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Component.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Component.java 26 Jun 2009 15:39:10 -0000 1.9 --- Component.java 12 Feb 2010 11:44:28 -0000 1.10 *************** *** 114,117 **** --- 114,121 ---- Instance instance = new Instance(space.getName() + " instance "); instance.setProto(space); + ParameterBlock block = space.getParameters(); + if (block != null) { + instance.setParameters(block.copy()); + } return instance; } Index: ParameterBlock.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ParameterBlock.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ParameterBlock.java 9 Sep 2009 12:51:32 -0000 1.18 --- ParameterBlock.java 12 Feb 2010 11:44:28 -0000 1.19 *************** *** 215,217 **** --- 215,229 ---- return buffer.toString(); } + + /** + * + * @return copy of this parameterblock + */ + public ParameterBlock copy() { + ParameterBlock copy = new ParameterBlock(); + for (Attribute current : parameters) { + copy.add(current.copy()); + } + return copy; + } } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.184 retrieving revision 1.185 diff -C2 -d -r1.184 -r1.185 *** Project.java 5 Feb 2010 13:32:50 -0000 1.184 --- Project.java 12 Feb 2010 11:44:28 -0000 1.185 *************** *** 21,24 **** --- 21,26 ---- import java.net.Socket; import java.net.SocketAddress; + import java.net.URL; + import java.net.URLConnection; import java.text.DecimalFormat; import java.util.ArrayList; *************** *** 44,47 **** --- 46,52 ---- import net.sourceforge.bprocessor.model.bridge.Serializer; import net.sourceforge.bprocessor.model.bridge.UnSerializer; + import net.sourceforge.bprocessor.model.brunata.io.BPersistence; + import net.sourceforge.bprocessor.model.brunata.io.XMLDocument; + import net.sourceforge.bprocessor.model.brunata.io.DocumentParser; import net.sourceforge.bprocessor.model.modellor.InnerWallModellor; import net.sourceforge.bprocessor.model.modellor.ModelBathModellor2; *************** *** 81,84 **** --- 86,91 ---- private static final int PORT = 8800; + private static boolean brunata; + private Tesselator tesselator; *************** *** 176,180 **** public void setMeasures(List<SensorItem> data) { measures = data; - index = 0; } --- 183,186 ---- *************** *** 235,240 **** String h = format.format(data.humimdity()); String info = "Temperatur: " + t + " C\n" + "Relativ luftfugtighed: " + h + "ä\n"; ! sensor.setDescription(info); if (data.temperature() < 18 && data.humimdity() > 70) { --- 241,261 ---- String h = format.format(data.humimdity()); + String id = ""; + if (data.id().equals("2501858")) { + id = "3134"; + } else if (data.id().equals("2501861")) { + id = "3132"; + } else if (data.id().equals("2501863")) { + id = "3119"; + } else if (data.id().equals("2501864")) { + id = "3138"; + } else if (data.id().equals("2501865")) { + id = "3127"; + } + + String header = "Internal ID: " + data.id() + "\nExternal ID: " + id + "\n"; + String info = "Temperatur: " + t + " C\n" + "Relativ luftfugtighed: " + h + "ä\n"; ! sensor.setDescription(header + info); if (data.temperature() < 18 && data.humimdity() > 70) { *************** *** 1139,1143 **** } else if (a.getName().equals("Export Path")) { setExportPath((String)a.getValue()); ! } } changed(this); --- 1160,1166 ---- } else if (a.getName().equals("Export Path")) { setExportPath((String)a.getValue()); ! } else if (a.getName().equals("Brunata Server")) { ! brunata = ((Boolean) a.getValue()).booleanValue(); ! } } changed(this); *************** *** 1156,1159 **** --- 1179,1183 ---- res.add(new Attribute("Export", Boolean.valueOf(doExport))); res.add(new Attribute("Export Path", getExportPath())); + res.add(new Attribute("Brunata Server", Boolean.valueOf(brunata))); res.add(new Attribute("Script", script)); return res; *************** *** 2014,2018 **** */ public void updateSensors() { ! sensor.update(); } } --- 2038,2144 ---- */ public void updateSensors() { ! if (SENSE) { ! sensor.update(); ! } ! if (brunata) { ! fetch(); ! } ! } ! ! private void fetch() { ! try { ! List<SensorItem> items1 = process(2501858); ! List<SensorItem> items2 = process(2501861); ! List<SensorItem> items3 = process(2501863); ! List<SensorItem> items4 = process(2501864); ! List<SensorItem> items5 = process(2501865); ! ! List<SensorItem> result = new LinkedList(); ! ! Iterator<SensorItem> iter1 = items1.iterator(); ! Iterator<SensorItem> iter2 = items2.iterator(); ! Iterator<SensorItem> iter3 = items3.iterator(); ! Iterator<SensorItem> iter4 = items4.iterator(); ! Iterator<SensorItem> iter5 = items5.iterator(); ! for (int i = 0; i < items1.size(); i++) { ! if (iter1.hasNext()) { ! result.add(iter1.next()); ! } ! if (iter2.hasNext()) { ! result.add(iter2.next()); ! } ! if (iter3.hasNext()) { ! result.add(iter3.next()); ! } ! if (iter4.hasNext()) { ! result.add(iter4.next()); ! } ! if (iter5.hasNext()) { ! result.add(iter5.next()); ! } ! } ! setMeasures(result); ! } catch (Exception e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } ! } ! ! /** ! * ! * @param url URL ! * @return XMLDocument ! * @throws Exception Error ! */ ! public static XMLDocument fetch(URL url) throws Exception { ! URLConnection connection = url.openConnection(); ! DocumentParser parser = new DocumentParser(); ! InputStream input = connection.getInputStream(); ! XMLDocument document = parser.parse(input); ! input.close(); ! return document; } + + private URL address(long id) 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 address = www + login + what + id + type; + return new URL(address); + } + + private List<SensorItem> process(long id) throws Exception { + URL url = address(id); + XMLDocument document = fetch(url); + BPersistence persistence = new BPersistence(); + List<BPersistence.Serie> series = persistence.internalize(document); + BPersistence.Serie leader = series.get(0); + List<SensorItem> items = new ArrayList(); + for (int i = 0; i < leader.size(); i++) { + SensorItem item = new SensorItem(); + item.setId(String.valueOf(id)); + items.add(item); + } + for (BPersistence.Serie current : series) { + String type = current.getType(); + int i = 0; + for (BPersistence.DataItem data : current.items()) { + SensorItem item = items.get(i); + if (type.equals("TEMPERATURE")) { + item.setTemparature(data.value); + item.setTime(data.timestamp); + } else if (type.equals("HUMIDITY")) { + item.setHumidity(data.value); + } + i++; + } + } + for (SensorItem current : items) { + System.out.println(current); + } + return items; + } + } + Index: Item.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Item.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Item.java 18 Sep 2009 09:09:06 -0000 1.3 --- Item.java 12 Feb 2010 11:44:28 -0000 1.4 *************** *** 616,620 **** } res.add(new Attribute("Material", new Reference(material(), materials))); - res.add(new Attribute("Closed", Boolean.valueOf(closed()))); res.add(new Attribute("Description", getDescription())); if (getModellor() != null) { --- 616,619 ---- Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** Command.java 9 Sep 2009 12:51:32 -0000 1.80 --- Command.java 12 Feb 2010 11:44:28 -0000 1.81 *************** *** 130,133 **** --- 130,166 ---- + + /** + * + * + */ + public static class PropertyCommand extends Command { + private Geometric target; + + /** + * + * @param target Geometric + */ + public PropertyCommand(Geometric target) { + this.target = target; + parameters.put("name", ""); + } + + /** + * {@inheritDoc} + */ + public void evaluate() { + ParameterBlock block = target.getParameters(); + if (block == null) { + block = new ParameterBlock(); + target.setParameters(block); + } + String name = (String) parameters.get("name"); + if (name.length() > 0) { + block.put(name, ""); + } + } + + } /** * |