Fix some issues

This commit is contained in:
Atos1337 2021-12-04 00:52:22 +03:00
parent cfd7bce2f3
commit b79ad40a9b
4 changed files with 10 additions and 12 deletions

View File

@ -13,7 +13,7 @@ import space.kscience.dataforge.names.Name
import space.kscience.dataforge.values.Value import space.kscience.dataforge.values.Value
import space.kscience.dataforge.values.ValueType import space.kscience.dataforge.values.ValueType
public fun PropertyChangedMessage.toEntity(transaction: StoreTransaction): Entity { internal fun PropertyChangedMessage.toEntity(transaction: StoreTransaction): Entity {
val entity = transaction.newEntity("PropertyChangedMessage") val entity = transaction.newEntity("PropertyChangedMessage")
entity.setProperty("property", property) entity.setProperty("property", property)
entity.setProperty("value", value.toString()) entity.setProperty("value", value.toString())
@ -24,7 +24,7 @@ public fun PropertyChangedMessage.toEntity(transaction: StoreTransaction): Entit
return entity return entity
} }
public fun Entity.toPropertyChangedMessage(): PropertyChangedMessage? { internal fun Entity.toPropertyChangedMessage(): PropertyChangedMessage? {
if (getProperty("property") == null || getProperty("value") == null || getProperty("sourceDevice") == null) { if (getProperty("property") == null || getProperty("value") == null || getProperty("sourceDevice") == null) {
return null return null
} }
@ -39,7 +39,7 @@ public fun Entity.toPropertyChangedMessage(): PropertyChangedMessage? {
) )
} }
public fun <T> MagixMessage<T>.toEntity(transaction: StoreTransaction): Entity { internal fun <T> MagixMessage<T>.toEntity(transaction: StoreTransaction): Entity {
val entity = transaction.newEntity("MagixMessage") val entity = transaction.newEntity("MagixMessage")
entity.setProperty("format", format) entity.setProperty("format", format)
entity.setProperty("origin", origin) entity.setProperty("origin", origin)
@ -54,7 +54,7 @@ public fun <T> MagixMessage<T>.toEntity(transaction: StoreTransaction): Entity {
return entity return entity
} }
public fun Entity.toMagixMessage(): MagixMessage<PropertyChangedMessage>? { internal fun Entity.toMagixMessage(): MagixMessage<PropertyChangedMessage>? {
if (getProperty("format") == null || getProperty("origin") == null) { if (getProperty("format") == null || getProperty("origin") == null) {
return null return null
} }

View File

@ -5,11 +5,8 @@ import kotlinx.datetime.Instant
import ru.mipt.npm.controls.api.PropertyChangedMessage import ru.mipt.npm.controls.api.PropertyChangedMessage
import ru.mipt.npm.controls.xodus.toPropertyChangedMessage import ru.mipt.npm.controls.xodus.toPropertyChangedMessage
//selectDeviceMessagesInRange public fun StoreTransaction.selectPropertyChangedMessagesFromRange(
public fun StoreTransaction.fromTo( range: ClosedRange<Instant>
range: ClosedRange<Instant>,
// from: Instant,
// to: Instant,
): List<PropertyChangedMessage> = find( ): List<PropertyChangedMessage> = find(
"PropertyChangedMessage", "PropertyChangedMessage",
"time", "time",

View File

@ -55,7 +55,7 @@ internal class QueriesTest {
@Test @Test
fun testFromTo() { fun testFromTo() {
assertEquals(propertyChangedMessages.subList(0, 2).toSet(), entityStore.computeInReadonlyTransaction { assertEquals(propertyChangedMessages.subList(0, 2).toSet(), entityStore.computeInReadonlyTransaction {
it.fromTo( Instant.fromEpochMilliseconds(1000)..Instant.fromEpochMilliseconds(1500)) it.selectPropertyChangedMessagesFromRange( Instant.fromEpochMilliseconds(1000)..Instant.fromEpochMilliseconds(1500))
}.toSet()) }.toSet())
} }

View File

@ -26,6 +26,7 @@ import ru.mipt.npm.magix.server.startMagixServer
import space.kscience.dataforge.context.* import space.kscience.dataforge.context.*
import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.Meta
import tornadofx.* import tornadofx.*
import java.nio.file.Paths
class VirtualCarController : Controller(), ContextAware { class VirtualCarController : Controller(), ContextAware {
@ -49,12 +50,12 @@ class VirtualCarController : Controller(), ContextAware {
virtualCar = deviceManager.install("virtual-car", VirtualCar) virtualCar = deviceManager.install("virtual-car", VirtualCar)
//starting magix event loop and connect it to entity store //starting magix event loop and connect it to entity store
magixEntityStore = PersistentEntityStores.newInstance("/home/marvel1337/2021/SCADA/.server_messages") magixEntityStore = PersistentEntityStores.newInstance(Paths.get(".server_messages").toFile())
magixServer = startMagixServer(enableRawRSocket = true, enableZmq = true) { flow -> magixServer = startMagixServer(enableRawRSocket = true, enableZmq = true) { flow ->
flow.storeInXodus(magixEntityStore as PersistentEntityStore) flow.storeInXodus(magixEntityStore as PersistentEntityStore)
} }
magixVirtualCar = deviceManager.install("magix-virtual-car", MagixVirtualCar) magixVirtualCar = deviceManager.install("magix-virtual-car", MagixVirtualCar)
deviceEntityStore = PersistentEntityStores.newInstance("/home/marvel1337/2021/SCADA/.messages") deviceEntityStore = PersistentEntityStores.newInstance(Paths.get(".messages").toFile())
//connect to device entity store //connect to device entity store
xodusStorageJob = deviceManager.connectXodus(deviceEntityStore as PersistentEntityStore) xodusStorageJob = deviceManager.connectXodus(deviceEntityStore as PersistentEntityStore)
//Create mongo client and connect to MongoDB //Create mongo client and connect to MongoDB