[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/sense/monitor TargetMonitor.java, 1
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2010-11-26 14:20:39
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/sense/monitor In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv26351/src/net/sourceforge/bprocessor/model/sense/monitor Modified Files: TargetMonitor.java SensorMonitor.java MonitorManager.java SensorHistory.java Log Message: Index: MonitorManager.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/sense/monitor/MonitorManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MonitorManager.java 31 Aug 2010 13:48:03 -0000 1.1 --- MonitorManager.java 26 Nov 2010 14:20:31 -0000 1.2 *************** *** 30,32 **** --- 30,56 ---- return monitor; } + + public void check() { + for (TargetMonitor current : targetMap.values()) { + current.check(); + } + } + + public void fetchHistoric() { + for (TargetMonitor current : targetMap.values()) { + current.fetchHistoric(); + } + } + + public void clearHistoric() { + for (TargetMonitor current : targetMap.values()) { + current.clearHistoric(); + } + } + + public void checkMold() { + for (TargetMonitor current : targetMap.values()) { + current.checkMold(); + } + } } Index: TargetMonitor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/sense/monitor/TargetMonitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TargetMonitor.java 31 Aug 2010 13:48:03 -0000 1.1 --- TargetMonitor.java 26 Nov 2010 14:20:31 -0000 1.2 *************** *** 7,15 **** --- 7,20 ---- import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Entity; + import net.sourceforge.bprocessor.model.Operation; import net.sourceforge.bprocessor.model.Parametric; + import net.sourceforge.bprocessor.model.Project; + import net.sourceforge.bprocessor.model.sense.core.Measurement; import net.sourceforge.bprocessor.model.sense.core.Sensor; import net.sourceforge.bprocessor.model.sense.core.Target; public class TargetMonitor extends Entity implements Parametric { + + private Target target; private List<SensorMonitor> monitors; *************** *** 32,35 **** --- 37,64 ---- List<Attribute> attributes = new LinkedList<Attribute>(); attributes.add(new Attribute("Name", target.getId(), false)); + attributes.add(new Attribute("Temperature", target.getTemperature(), false)); + attributes.add(new Attribute("Humidity", target.getHumidity(), false)); + if (target.humidityAlarm) { + attributes.add(new Attribute("Clear Humidity Alarm", new Operation() { + public void perform() { + target.humidityAlarm = false; + } + })); + } + if (target.temperatureAlarm) { + attributes.add(new Attribute("Clear Temperature Alarm", new Operation() { + public void perform() { + target.temperatureAlarm = false; + } + })); + } + if (target.skimmelAlarm) { + attributes.add(new Attribute("Clear Mold Alarm", new Operation() { + public void perform() { + target.skimmelAlarm = false; + } + })); + } + // attributes.add(new Attribute("Name", target.getId(), false)); return attributes; } *************** *** 39,47 **** public String title() { ! return "Target"; } public String getName() { ! return "Target " + target.getId(); } --- 68,76 ---- public String title() { ! return "Mote"; } public String getName() { ! return "Mote " + target.getId(); } *************** *** 51,53 **** --- 80,178 ---- } } + + public void check() { + target.check(); + } + + public List<Measurement> getTemperatures() { + Sensor sensor = target.find("temperature"); + if (sensor != null) { + SensorMonitor monitor = get(sensor); + if (monitor != null) { + List<DataSet> lst = new LinkedList(); + List<Measurement> meas = new LinkedList<Measurement>(); + monitor.collect(lst); + for (DataSet current : lst) { + for (DataItem item : current.getItems()) { + meas.add(item.getMeasureMent()); + } + } + if (!meas.isEmpty()) { + return meas; + } + } + } + return target.getTemperatures(); + } + + private SensorMonitor get(Sensor sensor) { + for (SensorMonitor current : monitors) { + if (current.getSensor() == sensor) { + return current; + } + } + return null; + } + + public List<Measurement> getHumidities() { + System.out.println("find humidity sensor"); + Sensor sensor = target.find("humidity"); + + if (sensor != null) { + System.out.println("find monitor in " + sensor.getType()); + SensorMonitor monitor = get(sensor); + if (monitor != null) { + System.out.println("collect measurements"); + List<DataSet> lst = new LinkedList(); + List<Measurement> meas = new LinkedList<Measurement>(); + monitor.collect(lst); + for (DataSet current : lst) { + for (DataItem item : current.getItems()) { + meas.add(item.getMeasureMent()); + } + } + if (!meas.isEmpty()) { + System.out.println("returning measurements"); + return meas; + } + } + } + return target.getHumdiities(); + } + + public void fetchHistoric() { + for (SensorMonitor current: monitors) { + current.fetchHistoric(); + } + } + + public void clearHistoric() { + target.skimmelAlarm = false; + for (SensorMonitor current: monitors) { + current.clearHistoric(); + } + } + + public void checkMold() { + List<Measurement> temps = getTemperatures(); + List<Measurement> hums = getHumidities(); + + double t = 0; + for (Measurement current : temps) { + t = t + Double.valueOf(current.getValue()); + } + t = t / temps.size(); + target.average = t; + target.limit = Project.moldtable.get(t); + boolean alarm = true; + for (Measurement current : hums) { + double h = Double.valueOf(current.getValue()); + if (h < target.limit) { + alarm = false; + } + } + target.skimmelAlarm = alarm; + target.temperatureAlarm = false; + target.humidityAlarm = false; + } } Index: SensorHistory.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/sense/monitor/SensorHistory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SensorHistory.java 31 Aug 2010 13:48:03 -0000 1.1 --- SensorHistory.java 26 Nov 2010 14:20:31 -0000 1.2 *************** *** 52,55 **** --- 52,92 ---- } + public void fetchHistoric(boolean adjust) { + try { + DateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); + Date f = format.parse("2010.05.01 08:00:00"); + Date t = format.parse("2010.06.01 08:00:00"); + System.out.println("fetch " + from + " => " + to); + History history = TargetManager.instance().getHistory(); + List<Measurement> result = history.fetch(target, sensor, f, t); + if (adjust) { + if (sensor.getType().equals("temperature")) { + for (Measurement current : result) { + double temperature = Double.valueOf(current.getValue()); + temperature = temperature + 5; + current.setValue(String.valueOf(temperature)); + } + } else { + for (Measurement current : result) { + double humidity = Double.valueOf(current.getValue()); + humidity = humidity + 10; + while (humidity < 89) { + humidity = humidity + 10; + } + current.setValue(String.valueOf(humidity)); + } + } + } + data = new DataSet(sensor, result); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void clearHistoric() { + data = new DataSet(sensor, new LinkedList<Measurement>()); + } + public void delete() { } Index: SensorMonitor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/sense/monitor/SensorMonitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SensorMonitor.java 31 Aug 2010 13:48:03 -0000 1.1 --- SensorMonitor.java 26 Nov 2010 14:20:31 -0000 1.2 *************** *** 45,47 **** --- 45,65 ---- sensorHistory.collect(lst); } + + public Sensor getSensor() { + return sensor; + } + + public void fetchHistoric() { + if (target.getId().equals("3890735107")) { + sensorHistory.fetchHistoric(true); + } else { + sensorHistory.fetchHistoric(false); + } + } + + public void clearHistoric() { + sensorHistory.clearHistoric(); + } + + } |