(music)
>> I am LUCKYNO7EVIN, welcome to the channel.
I'm also known as Andy Morrell.
We are doing a little bit of a different stream today.
We are looking at Azure or Azure.
And data behind it
and trying to put data into it.
What we've done so far
is we have created a SDK
called S7evemetry.
Now, S7evemetry is actually a telemetry application
and extracts telemetry data
from a lot of racing simulation games.
And you can see one of two solutions I've got open.
So we have 2017, '18, '19 and '20.
We have F1_Legacy,
which is what 2016 started as.
I think from 2010, they started to put telemetry in
but 2016 was the base one
that sort of is compatible throughout what they do now.
We have got Forza Horizon 4 as I said
and Forza Motorsport 7.
And that's what we have in the SDK right now.
At the moment, telemetry doesn't actually do that much.
So we have the listener
and all the hosted service stuff.
So we've got out UDP listener.
What we'll do is we'll comment that out.
And we'll uncomment 2019.
And let's start up this application,
trying to show you what's going on.
There we go.
And look at that.
We have telemetry data coming through.
As you can see,
we do have that telemetry data coming through.
That is what we're doing.
That is the sort of data we can get.
Differential adjustment on throttle.
Differential adjustment off the throttle.
FrontCamber, RearCamber.
It's got all, basically the setup for the car.
And I can grab that data.
Let's put this data into a database.
So at the moment,
my application doesn't look like much
but there you go, that's the application.
It's got a button there
but if I click me,
it'll go to Twitch,
ask me to sign in to S7evemetry Sim Racing.
I authorize the app.
I reopen that.
That won't work.
And then that's it, you're authenticated.
That's all it does right now.
And that is the application
that's gonna start sending your data to Twitch
when it receives it.
So this is what we want to do.
But we can't send it directly to Twitch.
What we're going to be doing is directly sending it
to our server first, so then we can fiddle with it
and then push it forward to where we want to.
If you go into your Azure dashboard,
just create a new resource.
Cosmos DB has a few plans
but what we're gonna do
is we're just going to create a new one.
We are going to grab this
as the S7evemetry or S7evemetry group,
which I need to create.
So we'll go with non-production for now
and disable availability zones.
Let's grab networking, all networks, that's fine.
Backup policy, nope, not today.
Service-managed key.
That'll do.
So that's currently deploying.
So we're going back down to 2019
because that's the one we're using today.
So what we'll do is we've got this hosted service,
which currently just goes on start,
it goes and starts the data visualizer
where you get all the data coming in.
So what we'll do is we'll create something
along the lines of what we're going to do with this.
Okay, so we're creating our container here.
So what we're doing is we've created
our like a Cosmos DB account.
It's a consumption account.
So basically it's built on access
and we created our new database called S7evemetry.
And we have car lap data.
Basically we need to start getting data in there.
So what we'll do is we'll just do Data, Entities.
So what we have here
is we're gonna have to have import Newtonsoft.Json
So we have our Cosmos object.
Let's import that now.
There you go.
Now, the object type,
we don't really need to think about.
We need to think about the idea at some point
and then we have the object itself.
That object is going to be CarLap.
CarLap.
Now, we're pretty much going
to copy exactly the stuff we get from here.
So for our CarLap, we just use TimeSpan
'cause this is currently in seconds.
So we have that TimeSpan.
So BestLap, Sector1, Sector1.
So if we copy and paste all this as well,
this is what we're gonna end up with.
LapTime in seconds
and let's do a TimeSpan on that one.
CurrentLap in seconds.
LapDistance, delta in seconds for safety car.
CarRacePosition and LapNumber.
Let's convert these back to bytes
because that's just easier.
So that's what we're gonna sort of have
as our lap data.
We then need to actually be able to write that data.
So let's make a CarLap repository.
So what we'll do is we'll add a class.
We'll call it CarLapRepository.
Constructor.
And that has to have a CosmosClient come through.
So if we go back to NuGet packages
and add our new NuGet package.
Microsoft.azure.cosmos.
Install, there we go.
So this is going to be the CostmosClient
and what we want to do
is we want to get the correct container out of this.
And what we'll do is we'll do cosmosContainer
equals costmosClient.GetContainer.
Now, our database ID and container ID.
Now, our database is actually S7evemetry
and our container was CarLapData.
There we go.
And what we want to do
is we want to just save some data to it.
So we've got our console entities, yes.
And now our task is going to be threading tasks
and let's just bring in a carLap.
What we have to do is we want to create the object
that we wanna save.
Now, so what we'll do is we'll do var objectToSave
equals new, let's do CosmosObject
of CarLap where the Id
is equal to 4900522.
So what we need to do is we need to do int index
'cause we can have up to 22 cars' worth of data.
Object item is equal to carLap.
cosmosContainer.Upsert.
We have objectToSave
and the partition key.
What we need to do is we need
to have a string property of ChannelId
and that needs to be ChannelId.
So we have our repository to sort of send data now.
So what we're gonna do
is we're going to create a new folder
and call it our CosmosDemo.
Our CosmosDemo is going to have a hosted service,
similar to this one actually.
We'll do that and call it CosmosDemoHostedService.
What we'll do is we'll just only have one
other class to this.
Cosmos DB, CosmosDemoCarLap.
Again, let's make that public.
Now, this CosmosDemoCarLap that's in here
is going to be similar to this like EventData.
So it's going to be an observer
but it's not gonna be an observer of EventData,
it should be CarLap.
Now, this doesn't currently implement what we want it to.
So let's just implement that abstract class
and let's bring that into here.
So that's going to be doing that sort of thing.
We're gonna go CarLap.Start and CarLap.Stop.
We're going to take the start
and stop from the data visualizer.
So we'll just copy and paste those.
We get rid of those two
and basically what we're doing
is we're subscribing to ourself.
Instead of doing this subscription here,
and listening on that,
getting the listener to start,
we do that in the HostedService.Start here.
And what we do is we pass in the cancellationToken.
We don't need to do the CosmosStart.
We don't need to do the CostmosFinish.
Get rid of that.
We get rid of the Listen.
We get rid of the Subscribe and Unsubscribe.
And on Start and Stop,
we want to actually deal with the CarLap.
So in here when we're bringing in the CarDemo,
we actually want that in here
to do the that .Subscribe.
Hey, there we go.
So in here, we pass in the listener like that.
Down here we do cosmosCarLap.Unsubscribe
and then we want the CarLapRepository.
So we have that going there.
We now need to change the program a bit
so it's not using any of this stuff.
We need to add CosmosDemoCarLap,
CosmosDemoPostedService.
CarLapRepository.
So what we're doing here
is we are doing a Cosmos Client Builder.
So we have the CarLapRepository,
you have the CarLapDemo and the HostedService.
We also have the CosmosClient coming in
and added, we have the listener ready to go.
So off screen,
I am now playing F1 2019.
And there we go.
That worked.
Instantaneous data.
So thank you very much for everyone for being here.
I've been LUCKYNO7EVIN.
Bye for now.