Search in sources :

Example 1 with IdentifierFragment

use of me.retrodaredevil.solarthing.packets.identification.IdentifierFragment in project solarthing by wildmountainfarms.

the class DefaultIdentificationCacheCreator method createFrom.

@Override
public IdentificationCacheDataPacket<T> createFrom(String sourceId, List<InstancePacketGroup> packetGroups, Instant periodStart, Duration periodDuration) {
    Class<U> acceptedType = identificationCacheNodeCreator.getAcceptedType();
    Map<String, Map<IdentifierFragment, List<TimestampedPacket<U>>>> mappedPackets = convertPackets(packetGroups, acceptedType);
    Map<IdentifierFragment, List<TimestampedPacket<U>>> identifierFragmentMap = mappedPackets.getOrDefault(sourceId, Collections.emptyMap());
    List<IdentificationCacheNode<T>> nodes = new ArrayList<>(identifierFragmentMap.size());
    for (Map.Entry<IdentifierFragment, List<TimestampedPacket<U>>> entry : identifierFragmentMap.entrySet()) {
        IdentifierFragment identifierFragment = entry.getKey();
        List<TimestampedPacket<U>> packets = entry.getValue();
        IdentificationCacheNode<T> node = identificationCacheNodeCreator.create(identifierFragment, packets, periodStart, periodDuration);
        nodes.add(node);
    }
    return new DefaultIdentificationCacheDataPacket<>(periodStart.toEpochMilli(), periodDuration.toMillis(), sourceId, identificationCacheNodeCreator.getCacheName(), nodes);
}
Also used : DefaultIdentificationCacheDataPacket(me.retrodaredevil.solarthing.type.cache.packets.DefaultIdentificationCacheDataPacket) IdentificationCacheNode(me.retrodaredevil.solarthing.type.cache.packets.IdentificationCacheNode) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) TimestampedPacket(me.retrodaredevil.solarthing.packets.TimestampedPacket)

Example 2 with IdentifierFragment

use of me.retrodaredevil.solarthing.packets.identification.IdentifierFragment in project solarthing by wildmountainfarms.

the class DefaultIdentificationCacheCreator method convertPackets.

@SuppressWarnings("unchecked")
private static <T extends Identifiable> Map<String, Map<IdentifierFragment, List<TimestampedPacket<T>>>> convertPackets(List<? extends FragmentedPacketGroup> packetGroups, Class<T> acceptedType) {
    Map<String, Map<IdentifierFragment, List<TimestampedPacket<T>>>> r = new HashMap<>();
    for (FragmentedPacketGroup packetGroup : packetGroups) {
        for (Packet packet : packetGroup.getPackets()) {
            if (!acceptedType.isInstance(packet)) {
                continue;
            }
            T identifiablePacket = (T) packet;
            String sourceId = packetGroup.getSourceId(packet);
            int fragmentId = packetGroup.getFragmentId(packet);
            Identifier identifier = identifiablePacket.getIdentifier();
            IdentifierFragment identifierFragment = IdentifierFragment.create(fragmentId, identifier);
            List<TimestampedPacket<T>> list = r.computeIfAbsent(sourceId, k -> new HashMap<>()).computeIfAbsent(identifierFragment, k -> new ArrayList<>());
            long dateMillis = packetGroup.getDateMillisOrKnown(packet);
            list.add(new TimestampedPacket<>(identifiablePacket, dateMillis));
        }
    }
    return r;
}
Also used : FragmentedPacketGroup(me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup) Packet(me.retrodaredevil.solarthing.packets.Packet) Identifiable(me.retrodaredevil.solarthing.packets.identification.Identifiable) java.util(java.util) DefaultIdentificationCacheDataPacket(me.retrodaredevil.solarthing.type.cache.packets.DefaultIdentificationCacheDataPacket) IdentificationCacheNode(me.retrodaredevil.solarthing.type.cache.packets.IdentificationCacheNode) FragmentedPacketGroup(me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup) IdentificationCacheDataPacket(me.retrodaredevil.solarthing.type.cache.packets.IdentificationCacheDataPacket) Instant(java.time.Instant) InstancePacketGroup(me.retrodaredevil.solarthing.packets.collection.InstancePacketGroup) Identifier(me.retrodaredevil.solarthing.packets.identification.Identifier) IdentificationCacheData(me.retrodaredevil.solarthing.type.cache.packets.data.IdentificationCacheData) Duration(java.time.Duration) Objects.requireNonNull(java.util.Objects.requireNonNull) TimestampedPacket(me.retrodaredevil.solarthing.packets.TimestampedPacket) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) Packet(me.retrodaredevil.solarthing.packets.Packet) DefaultIdentificationCacheDataPacket(me.retrodaredevil.solarthing.type.cache.packets.DefaultIdentificationCacheDataPacket) IdentificationCacheDataPacket(me.retrodaredevil.solarthing.type.cache.packets.IdentificationCacheDataPacket) TimestampedPacket(me.retrodaredevil.solarthing.packets.TimestampedPacket) Identifier(me.retrodaredevil.solarthing.packets.identification.Identifier) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) TimestampedPacket(me.retrodaredevil.solarthing.packets.TimestampedPacket)

Example 3 with IdentifierFragment

use of me.retrodaredevil.solarthing.packets.identification.IdentifierFragment in project solarthing by wildmountainfarms.

the class PacketFinder method updateWithRange.

private void updateWithRange(long queryStart, long queryEnd) {
    List<? extends InstancePacketGroup> rawPackets = simpleQueryHandler.queryStatus(queryStart, queryEnd, null);
    synchronized (cacheMap) {
        for (InstancePacketGroup instancePacketGroup : rawPackets) {
            int fragmentId = instancePacketGroup.getFragmentId();
            for (Packet packet : instancePacketGroup.getPackets()) {
                if (packet instanceof Identifiable) {
                    Identifiable identifiable = (Identifiable) packet;
                    IdentifierFragment packetIdentifierFragment = IdentifierFragment.create(fragmentId, identifiable.getIdentifier());
                    cacheMap.putIfAbsent(packetIdentifierFragment, identifiable);
                }
            }
        }
    }
}
Also used : InstancePacketGroup(me.retrodaredevil.solarthing.packets.collection.InstancePacketGroup) Packet(me.retrodaredevil.solarthing.packets.Packet) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) Identifiable(me.retrodaredevil.solarthing.packets.identification.Identifiable)

Example 4 with IdentifierFragment

use of me.retrodaredevil.solarthing.packets.identification.IdentifierFragment in project solarthing by wildmountainfarms.

the class PVOutputHandler method getStatus.

public AddStatusParameters getStatus(long dayStartTimeMillis, List<FragmentedPacketGroup> packetGroupList) {
    FragmentedPacketGroup latestPacketGroup = packetGroupList.get(packetGroupList.size() - 1);
    LOGGER.debug("Continuing with the latest packet group. Day start: " + dayStartTimeMillis);
    AddStatusParametersBuilder addStatusParametersBuilder = createStatusBuilder(zoneId, latestPacketGroup.getDateMillis());
    setStatusPowerValues(addStatusParametersBuilder, latestPacketGroup);
    setStatusEnergyValues(addStatusParametersBuilder, packetGroupList, AccumulationConfig.createDefault(dayStartTimeMillis));
    for (Packet packet : latestPacketGroup.getPackets()) {
        if (packet instanceof PVCurrentAndVoltage) {
            int fragmentId = latestPacketGroup.getFragmentId(packet);
            PVCurrentAndVoltage pvCurrentAndVoltage = (PVCurrentAndVoltage) packet;
            IdentifierFragment identifierFragment = IdentifierFragment.create(fragmentId, pvCurrentAndVoltage.getIdentifier());
            if (voltageIdentifierFragmentMatcher.matches(identifierFragment)) {
                float voltage = pvCurrentAndVoltage.getPVVoltage().floatValue();
                addStatusParametersBuilder.setVoltage(voltage);
            }
        } else if (packet instanceof TemperaturePacket) {
            int fragmentId = latestPacketGroup.getFragmentId(packet);
            TemperaturePacket temperaturePacket = (TemperaturePacket) packet;
            IdentifierFragment identifierFragment = IdentifierFragment.create(fragmentId, temperaturePacket.getIdentifier());
            if (temperatureIdentifierFragmentMatcher.matches(identifierFragment)) {
                float temperatureCelsius = temperaturePacket.getTemperatureCelsius();
                if (!TemperaturePacket.POSSIBLE_BAD_VALUES.contains(temperatureCelsius)) {
                    addStatusParametersBuilder.setTemperatureCelsius(temperatureCelsius);
                } else {
                    LOGGER.info("Not setting temperature: " + temperatureCelsius + " because it could be a bad reading");
                }
            }
        }
    }
    return addStatusParametersBuilder.build();
}
Also used : FragmentedPacketGroup(me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup) Packet(me.retrodaredevil.solarthing.packets.Packet) DailyFXPacket(me.retrodaredevil.solarthing.solar.outback.fx.extra.DailyFXPacket) TemperaturePacket(me.retrodaredevil.solarthing.misc.weather.TemperaturePacket) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) PVCurrentAndVoltage(me.retrodaredevil.solarthing.solar.common.PVCurrentAndVoltage) AddStatusParametersBuilder(me.retrodaredevil.solarthing.pvoutput.data.AddStatusParametersBuilder) TemperaturePacket(me.retrodaredevil.solarthing.misc.weather.TemperaturePacket)

Example 5 with IdentifierFragment

use of me.retrodaredevil.solarthing.packets.identification.IdentifierFragment in project solarthing by wildmountainfarms.

the class DefaultIdentificationCacheDataPacket method combineNodes.

private static <T extends IdentificationCacheData> List<IdentificationCacheNode<T>> combineNodes(List<IdentificationCacheNode<T>> first, List<IdentificationCacheNode<T>> second) {
    Map<IdentifierFragment, T> map = new HashMap<>();
    putOnMap(map, first);
    putOnMap(map, second);
    return map.entrySet().stream().map((identifierFragmentTEntry -> {
        IdentifierFragment identifierFragment = identifierFragmentTEntry.getKey();
        T data = identifierFragmentTEntry.getValue();
        return new IdentificationCacheNode<>(identifierFragment.getFragmentId(), data);
    })).collect(Collectors.toList());
}
Also used : IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment)

Aggregations

IdentifierFragment (me.retrodaredevil.solarthing.packets.identification.IdentifierFragment)8 Packet (me.retrodaredevil.solarthing.packets.Packet)5 TimestampedPacket (me.retrodaredevil.solarthing.packets.TimestampedPacket)3 FragmentedPacketGroup (me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup)3 Identifiable (me.retrodaredevil.solarthing.packets.identification.Identifiable)3 InstancePacketGroup (me.retrodaredevil.solarthing.packets.collection.InstancePacketGroup)2 DefaultIdentificationCacheDataPacket (me.retrodaredevil.solarthing.type.cache.packets.DefaultIdentificationCacheDataPacket)2 IdentificationCacheNode (me.retrodaredevil.solarthing.type.cache.packets.IdentificationCacheNode)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 TemperaturePacket (me.retrodaredevil.solarthing.misc.weather.TemperaturePacket)1 Identifier (me.retrodaredevil.solarthing.packets.identification.Identifier)1 KnownIdentifierFragment (me.retrodaredevil.solarthing.packets.identification.KnownIdentifierFragment)1 AddStatusParametersBuilder (me.retrodaredevil.solarthing.pvoutput.data.AddStatusParametersBuilder)1 PVCurrentAndVoltage (me.retrodaredevil.solarthing.solar.common.PVCurrentAndVoltage)1