mirror of
				https://github.com/zyphlar/LanternPowerMonitor.git
				synced 2024-03-08 14:07:47 +00:00 
			
		
		
		
	Allow calibration of all ports on a hub at once in addition to individually.
This commit is contained in:
		
							parent
							
								
									6c6f750691
								
							
						
					
					
						commit
						fa606cce84
					
				@ -85,7 +85,7 @@ public class CurrentMonitor {
 | 
			
		||||
		vRms /= samples.size();
 | 
			
		||||
		double oldVrms = _curCalibration * Math.sqrt(vRms);
 | 
			
		||||
		if (oldVrms < 20) {
 | 
			
		||||
			LOG.info("Could not get a valid voltage read, please check that your AC/AC transformer is connected");
 | 
			
		||||
			LOG.error("Could not get a valid voltage read, please check that your AC/AC transformer is connected");
 | 
			
		||||
			return 0.0;
 | 
			
		||||
		}
 | 
			
		||||
		double newCal = (_voltage/oldVrms) * _curCalibration;
 | 
			
		||||
@ -235,7 +235,7 @@ public class CurrentMonitor {
 | 
			
		||||
							vRms /= validSamples.size();
 | 
			
		||||
							vRms = hub.getVoltageCalibrationFactor() * Math.sqrt(vRms);
 | 
			
		||||
							int lowSampleRatio = (lowSamples * 100) / samples.getSampleCnt();
 | 
			
		||||
							double realPower = Math.abs((hub.getVoltageCalibrationFactor() * samples.getBreaker().getFinalCalibrationFactor() * pSum) / samples.getSampleCnt());
 | 
			
		||||
							double realPower = Math.abs((hub.getVoltageCalibrationFactor() * hub.getPortCalibrationFactor() * samples.getBreaker().getFinalCalibrationFactor() * pSum) / samples.getSampleCnt());
 | 
			
		||||
							if ((lowSampleRatio > 75) && realPower < 13.0)
 | 
			
		||||
								realPower = 0.0;
 | 
			
		||||
							if (samples.getBreaker().getPolarity() == BreakerPolarity.SOLAR)
 | 
			
		||||
 | 
			
		||||
@ -160,10 +160,8 @@ public class MonitorApp {
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
		monitor.submit(bluetoothConfig);
 | 
			
		||||
		if (NullUtils.isNotEmpty(config.getAuthCode())) {
 | 
			
		||||
		if (NullUtils.isNotEmpty(config.getAuthCode()))
 | 
			
		||||
			authCode = config.getAuthCode();
 | 
			
		||||
			//TODO: check auth code validity
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			HttpGet auth = new HttpGet(host + "auth");
 | 
			
		||||
			HttpPool.addBasicAuthHeader(auth, config.getUsername(), config.getPassword());
 | 
			
		||||
@ -187,7 +185,7 @@ public class MonitorApp {
 | 
			
		||||
					hub.setVoltageCalibrationFactor(newCal);
 | 
			
		||||
					config.setNeedsCalibration(false);
 | 
			
		||||
					ResourceLoader.writeFile(WORKING_DIR + "config.json", DaoSerializer.toJson(config));
 | 
			
		||||
					post(DaoSerializer.toZipBson(breakerConfig), "currentmonitor/config");
 | 
			
		||||
					post(DaoSerializer.toZipBson(breakerConfig), "config");
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			List<Breaker> breakers = breakerConfig.getBreakersForHub(config.getHub());
 | 
			
		||||
@ -341,6 +339,7 @@ public class MonitorApp {
 | 
			
		||||
				if (CollectionUtils.length(jar) == DaoSerializer.getInteger(meta, "size") && NullUtils.isEqual(DigestUtils.md5Hex(jar), DaoSerializer.getString(meta, "checksum"))) {
 | 
			
		||||
					LOG.info("Update downloaded, writing jar and restarting...");
 | 
			
		||||
					ResourceLoader.writeFile(WORKING_DIR + "lantern-currentmonitor.jar", jar);
 | 
			
		||||
					ConcurrencyUtils.sleep(5000);
 | 
			
		||||
					try {
 | 
			
		||||
						Runtime.getRuntime().exec("service currentmonitor restart");
 | 
			
		||||
					} catch (IOException _e) {
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@ package com.lanternsoftware.datamodel.currentmonitor;
 | 
			
		||||
 | 
			
		||||
import com.lanternsoftware.util.CollectionUtils;
 | 
			
		||||
import com.lanternsoftware.util.NullUtils;
 | 
			
		||||
import com.lanternsoftware.util.dao.DaoSerializer;
 | 
			
		||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
 | 
			
		||||
import com.lanternsoftware.util.dao.annotations.PrimaryKey;
 | 
			
		||||
 | 
			
		||||
@ -102,7 +103,7 @@ public class BreakerConfig {
 | 
			
		||||
 | 
			
		||||
	public String nextGroupId() {
 | 
			
		||||
		List<Integer> ids = CollectionUtils.transform(getAllBreakerGroupIds(), NullUtils::toInteger);
 | 
			
		||||
		return String.valueOf(CollectionUtils.getLargest(ids) + 1);
 | 
			
		||||
		return String.valueOf(DaoSerializer.toInteger(CollectionUtils.getLargest(ids)) + 1);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void addGroup(BreakerGroup _group) {
 | 
			
		||||
@ -116,7 +117,7 @@ public class BreakerConfig {
 | 
			
		||||
 | 
			
		||||
	public void removeInvalidGroups() {
 | 
			
		||||
		if (breakerGroups != null)
 | 
			
		||||
			breakerGroups.removeIf(_g->!_g.removeInvalidGroups());
 | 
			
		||||
			breakerGroups.removeIf(_g->!_g.removeInvalidGroups(CollectionUtils.transformToSet(panels, BreakerPanel::getIndex)));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getGroupIdForBreaker(Breaker _breaker) {
 | 
			
		||||
 | 
			
		||||
@ -10,6 +10,7 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
@DBSerializable()
 | 
			
		||||
public class BreakerGroup {
 | 
			
		||||
@ -169,11 +170,11 @@ public class BreakerGroup {
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public boolean removeInvalidGroups() {
 | 
			
		||||
	public boolean removeInvalidGroups(Set<Integer> _validPanels) {
 | 
			
		||||
		if (subGroups != null)
 | 
			
		||||
			subGroups.removeIf(_g->!_g.removeInvalidGroups());
 | 
			
		||||
			subGroups.removeIf(_g->!_g.removeInvalidGroups(_validPanels));
 | 
			
		||||
		if (breakers != null)
 | 
			
		||||
			breakers.removeIf(_b->(_b.getType() == null) || (_b.getType() == BreakerType.EMPTY) || (_b.getPort() < 1));
 | 
			
		||||
			breakers.removeIf(_b->(_b.getType() == null) || (_b.getType() == BreakerType.EMPTY) || (_b.isTandemBreaker() && (_b.getPort() < 1)) || !_validPanels.contains(_b.getPanel()));
 | 
			
		||||
		return CollectionUtils.isNotEmpty(subGroups) || CollectionUtils.isNotEmpty(breakers);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@ import com.lanternsoftware.util.dao.annotations.DBSerializable;
 | 
			
		||||
public class BreakerHub {
 | 
			
		||||
	private int hub;
 | 
			
		||||
	private double voltageCalibrationFactor;
 | 
			
		||||
	private double portCalibrationFactor;
 | 
			
		||||
	private int frequency;
 | 
			
		||||
	private String bluetoothMac;
 | 
			
		||||
 | 
			
		||||
@ -19,13 +20,21 @@ public class BreakerHub {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public double getVoltageCalibrationFactor() {
 | 
			
		||||
		return voltageCalibrationFactor;
 | 
			
		||||
		return voltageCalibrationFactor == 0.0?1.0:voltageCalibrationFactor;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setVoltageCalibrationFactor(double _voltageCalibrationFactor) {
 | 
			
		||||
		voltageCalibrationFactor = _voltageCalibrationFactor;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public double getPortCalibrationFactor() {
 | 
			
		||||
		return portCalibrationFactor == 0.0?1.0:portCalibrationFactor;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setPortCalibrationFactor(double _portCalibrationFactor) {
 | 
			
		||||
		portCalibrationFactor = _portCalibrationFactor;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public int getFrequency() {
 | 
			
		||||
		return frequency;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -27,6 +27,7 @@ public class BreakerHubSerializer extends AbstractDaoSerializer<BreakerHub>
 | 
			
		||||
		DaoEntity d = new DaoEntity();
 | 
			
		||||
		d.put("hub", _o.getHub());
 | 
			
		||||
		d.put("voltage_calibration_factor", _o.getVoltageCalibrationFactor());
 | 
			
		||||
		d.put("port_calibration_factor", _o.getPortCalibrationFactor());
 | 
			
		||||
		d.put("frequency", _o.getFrequency());
 | 
			
		||||
		d.put("bluetooth_mac", _o.getBluetoothMac());
 | 
			
		||||
		return d;
 | 
			
		||||
@ -38,6 +39,7 @@ public class BreakerHubSerializer extends AbstractDaoSerializer<BreakerHub>
 | 
			
		||||
		BreakerHub o = new BreakerHub();
 | 
			
		||||
		o.setHub(DaoSerializer.getInteger(_d, "hub"));
 | 
			
		||||
		o.setVoltageCalibrationFactor(DaoSerializer.getDouble(_d, "voltage_calibration_factor"));
 | 
			
		||||
		o.setPortCalibrationFactor(DaoSerializer.getDouble(_d, "port_calibration_factor"));
 | 
			
		||||
		o.setFrequency(DaoSerializer.getInteger(_d, "frequency"));
 | 
			
		||||
		o.setBluetoothMac(DaoSerializer.getString(_d, "bluetooth_mac"));
 | 
			
		||||
		return o;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user