Search in sources :

Example 1 with TimestampedPacket

use of me.retrodaredevil.solarthing.packets.TimestampedPacket 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 TimestampedPacket

use of me.retrodaredevil.solarthing.packets.TimestampedPacket 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 TimestampedPacket

use of me.retrodaredevil.solarthing.packets.TimestampedPacket in project solarthing by wildmountainfarms.

the class AccumulationUtil method mapPackets.

@SuppressWarnings("unchecked")
@Contract(pure = true)
public static <T extends Identifiable> Map<IdentifierFragment, List<TimestampedPacket<T>>> mapPackets(Class<T> clazz, List<? extends FragmentedPacketGroup> packetGroups) {
    Map<IdentifierFragment, List<TimestampedPacket<T>>> packetMap = new HashMap<>();
    for (FragmentedPacketGroup packetGroup : packetGroups) {
        for (Packet packet : packetGroup.getPackets()) {
            if (clazz.isInstance(packet)) {
                int fragmentId = packetGroup.getFragmentId(packet);
                T t = (T) packet;
                IdentifierFragment identifierFragment = IdentifierFragment.create(fragmentId, t.getIdentifier());
                List<TimestampedPacket<T>> packetList = packetMap.computeIfAbsent(identifierFragment, k -> new ArrayList<>());
                long dateMillis = packetGroup.getDateMillisOrKnown(packet);
                packetList.add(new TimestampedPacket<>(t, dateMillis));
            }
        }
    }
    return packetMap;
}
Also used : FragmentedPacketGroup(me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup) Packet(me.retrodaredevil.solarthing.packets.Packet) TimestampedPacket(me.retrodaredevil.solarthing.packets.TimestampedPacket) HashMap(java.util.HashMap) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) TimestampedPacket(me.retrodaredevil.solarthing.packets.TimestampedPacket) List(java.util.List) ArrayList(java.util.ArrayList) Contract(org.jetbrains.annotations.Contract)

Aggregations

TimestampedPacket (me.retrodaredevil.solarthing.packets.TimestampedPacket)3 IdentifierFragment (me.retrodaredevil.solarthing.packets.identification.IdentifierFragment)3 Packet (me.retrodaredevil.solarthing.packets.Packet)2 FragmentedPacketGroup (me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup)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 InstancePacketGroup (me.retrodaredevil.solarthing.packets.collection.InstancePacketGroup)1 Identifiable (me.retrodaredevil.solarthing.packets.identification.Identifiable)1 Identifier (me.retrodaredevil.solarthing.packets.identification.Identifier)1 IdentificationCacheDataPacket (me.retrodaredevil.solarthing.type.cache.packets.IdentificationCacheDataPacket)1 IdentificationCacheData (me.retrodaredevil.solarthing.type.cache.packets.data.IdentificationCacheData)1 Contract (org.jetbrains.annotations.Contract)1