Azure Digital Twin ADT Explorer - Multiple Rooms - azure-digital-twins

Setup ADT Explorer and Sample Floor & Room using this tutorial
Digital Twin Tutorial
In addition, added the additional rooms and created the relationship using these commands
CreateDigitalTwin dtmi:example:Room;2 room01 RoomName string Room01 Temperature double 70 HumidityLevel double 30
CreateDigitalTwin dtmi:example:Room;2 room02 RoomName string Room02 Temperature double 70 HumidityLevel double 30
CreateRelationship floor0 contains room01 relationship01
CreateRelationship floor0 contains room02 relationship02
When I run the query "SELECT floor, room FROM DIGITALTWINS floor JOIN room RELATED floor.contains where floor.$dtId = 'floor0'", I can see only the relation between floor0 and room0 and not with room01 and room02.
Any suggestions please.

Related

How can I implement a windowed rolling average with KSQL KTable correctly?

I am trying to implement a volume rolling average into KSQL.
Kafka currently ingests data from a producer into the topic "KLINES". This data is across multiple markets with a consistent format. I then create a stream from that data like so:
CREATE STREAM KLINESTREAM (market VARCHAR, open DOUBLE, high DOUBLE, low DOUBLE, close DOUBLE, volume DOUBLE, start_time BIGINT, close_time BIGINT, event_time BIGINT) \
WITH (VALUE_FORMAT='JSON', KAFKA_TOPIC='KLINES', TIMESTAMP='event_time', KEY='market');
I then create a table which calculates the average volume over the last 20 minutes for each market like so:
CREATE TABLE AVERAGE_VOLUME_TABLE_BY_MARKET AS \
SELECT CEIL(SUM(volume) / COUNT(*)) AS volume_avg, market FROM KLINESTREAM \
WINDOW HOPPING (SIZE 20 MINUTES, ADVANCE BY 5 SECONDS) \
GROUP BY market;
SELECT * FROM AVERAGE_VOLUME_TABLE_BY_MARKET LIMIT 1;
For clarity, produces:
1560647412620 | EXAMPLEMARKET : Window{start=1560647410000 end=-} | 44.0 | EXAMPLEMARKET
What I wish to have is a KSQL Table that will represent the current "kline" state of each market while also including that rolling average volume calculated in "AVERAGE_VOLUME_TABLE_BY_MARKET" KTable so I can perform analysis between current volume and the average rolling volume
I have tried to join like so:
SELECT K.market, K.open, K.high, K.low, K.close, K.volume, V.volume_avg \
FROM KLINESTREAM K \
LEFT JOIN AVERAGE_VOLUME_TABLE_BY_MARKET V \
ON K.market = V.market;
But obviously this results in an error as the "AVERAGE_VOLUME_TABLE_BY_MARKET" key includes the TimeWindow and also the market.
A serializer (key:
org.apache.kafka.streams.kstream.TimeWindowedSerializer) is not compatible to
the actual key type (key type: java.lang.String). Change the default Serdes in
StreamConfig or provide correct Serdes via method parameters.
Am I approaching this problem correctly?
What I want to achieve is:
Windowed Aggregate KTable + Kline Stream ->
KTable representing current market state
including average volume from the KTable
which displays the current market state possible in KSQL. Or must I use KStreams or another library to accomplish this?
A great aggregation example is here: https://www.confluent.io/stream-processing-cookbook/ksql-recipes/aggregating-data
Applicable to this example, how would I use the aggregate to compare to fresh data as it arrives in the KSQL Table?
Cheers, James
I believe what you're looking for may be LATEST_BY_OFFSET:
CREATE TABLE AVERAGE_VOLUME_TABLE_BY_MARKET AS
SELECT
market,
LATEST_BY_OFFSET(volume) AS volume,
CEIL(SUM(volume) / COUNT(*)) AS volume_avg
FROM KLINESTREAM
WINDOW HOPPING (SIZE 20 MINUTES, ADVANCE BY 5 SECONDS)
GROUP BY market;

How to count cypher labels with specific condition?

I have a graph database with information about different companies and their subsidiaries. Now my task is to display the structure of the company. This I have achieved with d3 and vertical tree.
But additionally I have to write summary statistics about the company that is currently displayed. Companies can be chosen from a dropdown list which is fetching this data dynamically via AJAX call.
I have to write in the same HTML a short summary like :
Total amount of subsidiaries for CompanyA: 300
Companies in Corporate Havens : 45%
Companies in Tax havens 5%
My database consists of two nodes: Company and Country, and the country has label like CH and TH.
CREATE (:TH:Country{name:'Nauru', capital:'Yaren', lng:166.920867,lat:-0.5477})
WITH 1 as dummy MATCH (a:Company), (b:Country) WHERE a.name=‘CompanyA ' AND b.name='Netherlands' CREATE (a)-[:IS_REGISTERED]->(b)
So how can I find amount of subsidiaries of CompanyA that are registered in corporate and tax havens? And how to pass this info further to html
I found different cypher queries to query all the labels as well as apocalyptic.stats but this does not allow me to filter on mother company. I appreciate help.
The cypher is good because you write a query almost in natural language (the query below may be incorrect - did not check, but the idea is clear):
MATCH (motherCompany:Company {name: 'CompanyA'})-[:HAS_SUBSIDIARY]->(childCompany:Company)
WITH motherCompany,
childCompany
MATCH (childCompany)-[:IS_REGISTERED]->(country:Country)
WITH motherCompany,
collect(labels(country)) AS countriesLabels
WITH motherCompany,
countriesLabels,
size([countryLabels IN countriesLabels WHERE 'TH' IN countryLabels ]) AS inTaxHeaven
RETURN motherCompany,
size(countriesLabels) AS total,
inTaxHeaven,
size(countriesLabels) - inTaxHeaven AS inCorporateHeaven

Find Distance using Latitude/Longitude using Neo4J

I have a CSV consisting of Places of Interest in one table and Other table consists of office locations of a company. Both the tables consist of Latitude and Longitude information as well.
Structure of CSV file consisting of Places of Interest
POI_Name Longitude Latitude City
POI_1 77.573957 12.970125 Bangalore
POI_2 77.579886 13.009582 Bangalore
POI_3 77.546688 13.023931 Chennai
Similarly we have a CSV file with office locations of a company
Office Longitude Latitude City
Office_1 78.324445 12.970125 Bangalore
Office_2 77.254555 13.234444 Chennai
Office_3 76.098438 14.135567 Bangalore
Both tables consists of thousands of records. Now I want to create a query in Neo4J that will give me top 5 Nearest place of interest to the office location (Passed as a parameter in the query) in the decreasing order at the run time.
As the distance bewteen two nodes every time will be the same, I recommend you parse all places vs all offices and create a "distance" relation with a value of distance in km or whatever between the nodes(placei,officej), then you only query the first n nearest nodes from another node (then you can run a query like: MATCH (p:Place)-[d:DISTANCE]->(o:Office{myoffice}) RETURN p,o,d ORDER BY d.km ASC LIMIT 5). You will save time and computational cost.
Anyway you can use something like the next query:
MATCH (p:Place), (o:Office {id:myoffice}) RETURN distance(point({latitude: p.latitude, longitude: p.longitude}), point({latitude: o.latitude, longitude: o.longitude})) / 1000.0 as km, p, o ORDER BY km ASC LIMIT 5

Neo4j percentage query

I recently had a Homework problem that I could not figure out how to even start let alone how to get each of the 1 letter purposes added together and have their % returned. I have included the Neo4j model as well as a list of the first few rows. The data showed the Taxon, Class, Order, Family, Genus if they were imported/exported and the purpose (example C. Aves imported for commercial purposes)
What % of trades fall under each purpose type (bred, captured, wild, zoo, etc...)
CLASS: ORDER: IMPORT/EXPORT: PURPOSE:
AVES Falconiforms 43 Exported S (Science)
Mammalia Carnivora 2 Exported H (hunting)
Reptilia Crocodylia 10 Imported S (Science)
Aves Anseriformes 2 Imported T (commercial)
Mammalia Primates 700 Exported T (commercial)
Neo4j Graph Dataset

Search four fields in YQL geo.places

We are currently using YQL to query geo data for towns and counties in the UK. At the moment, we can use the following query to find all towns named Boston:
select * from geo.places where text="boston" and placeTypeName="Town"
Demo
The issue is, that we would like to specify the county and country to generate more specific results. I have tried the following query, but it returns 0 results:
select * from geo.places where (text="boston" and placeTypeName="Town") and (text="lincolnshire" and placeTypeName="County")
Demo
How can I query 3 field types to return the results I need? Essentially, we would like to query the following fields:
text and placeTypeName="Town"
text and placeTypeName="County"
text and placeTypeName="Country"
This may be an option maybe:
https://developer.yahoo.com/blogs/ydnsevenblog/solving-location-based-services-needs-yahoo-other-technology-7952.html
As it mentions:
Turning text into a location
You can also turn a text (name) into a location using the following code:
yqlgeo.get('paris,fr',function(o){
alert(o.place.name+' ('+
o.place.centroid.latitude+','+
o.place.centroid.longitude+
')');
})
This wrapper call uses our Placemaker Service under the hood and automatically disambiguates for you. This means that Paris is Paris, France, and not Paris Hilton; London is London, England, and not Jack London.

Resources