C
C#2mo ago
eduardoA

Reatime update

Hello, I am using firestore, to store some values And I have a service, the get the value updated every second
private async void InitializeAsync() {
if (_firestoreDb != null) {
await LoadOrInitializeTurbineAsync();
InitializeTimer();
}
}

async Task LoadOrInitializeTurbineAsync() {
var turbinesRef = _firestoreDb!.Collection(collectionName);
var snapshot = await turbinesRef.GetSnapshotAsync();

if (snapshot.Count == 0) {
var turbine = new Turbine {
Id = "EC-G-SB",
Country = "Ecuador",
Name = "Estación Ciudadela Simón Bolívar",
Address = "Av. de las Américas, Guayaquil 090513, Ecuador",
Latitude = -2.151993,
Longitude = -79.886109,
};

turbine.RemovedCo2Kilograms = Math.Round(turbine.EnergyProduced * turbine.Co2EmissionOffset, 5);

var turbineDocRef = turbinesRef.Document(turbine.Id);
private async void InitializeAsync() {
if (_firestoreDb != null) {
await LoadOrInitializeTurbineAsync();
InitializeTimer();
}
}

async Task LoadOrInitializeTurbineAsync() {
var turbinesRef = _firestoreDb!.Collection(collectionName);
var snapshot = await turbinesRef.GetSnapshotAsync();

if (snapshot.Count == 0) {
var turbine = new Turbine {
Id = "EC-G-SB",
Country = "Ecuador",
Name = "Estación Ciudadela Simón Bolívar",
Address = "Av. de las Américas, Guayaquil 090513, Ecuador",
Latitude = -2.151993,
Longitude = -79.886109,
};

turbine.RemovedCo2Kilograms = Math.Round(turbine.EnergyProduced * turbine.Co2EmissionOffset, 5);

var turbineDocRef = turbinesRef.Document(turbine.Id);
private void InitializeTimer() {
_timer = new System.Timers.Timer(1000);
_timer.Elapsed += async (sender, e) => await UpdateCO2ValueAsync();
_timer.AutoReset = true;
_timer.Enabled = true;
}

private async Task UpdateCO2ValueAsync() {
var turbineRef = _firestoreDb!.Collection("turbines").Document("EC-G-SB");
var snapshot = await turbineRef.GetSnapshotAsync();
var turbine = snapshot.ConvertTo<Turbine>();
var beforeUpdate = turbine.RemovedCo2Kilograms;
turbine.RemovedCo2Kilograms = Math.Round(beforeUpdate + 0.0007, 5);
turbine.FinalCo2Removed = turbine.RemovedCo2Kilograms;
await turbineRef.SetAsync(turbine, SetOptions.Overwrite);

private void InitializeTimer() {
_timer = new System.Timers.Timer(1000);
_timer.Elapsed += async (sender, e) => await UpdateCO2ValueAsync();
_timer.AutoReset = true;
_timer.Enabled = true;
}

private async Task UpdateCO2ValueAsync() {
var turbineRef = _firestoreDb!.Collection("turbines").Document("EC-G-SB");
var snapshot = await turbineRef.GetSnapshotAsync();
var turbine = snapshot.ConvertTo<Turbine>();
var beforeUpdate = turbine.RemovedCo2Kilograms;
turbine.RemovedCo2Kilograms = Math.Round(beforeUpdate + 0.0007, 5);
turbine.FinalCo2Removed = turbine.RemovedCo2Kilograms;
await turbineRef.SetAsync(turbine, SetOptions.Overwrite);

[ObservableProperty]

public double finalCo2Removed;
[ObservableProperty]

public double finalCo2Removed;
that gets updated every second in the data in the database like this https://reccloud.com/u/edxlrsd I am trying to bind this value and see when the value rise in my collection view but when I bind I get 0
RecCloud
recording-2024-11-04-13-28-35.webm
RecCloud enables you to record, share, upload videos online and experience video collaboration.
From An unknown user
From An unknown user
2 Replies
Buddy
Buddy2mo ago
You can just use the Windows Snipping tool no need to use some random website to record which doesn't even have a video embed for Discord
eduardoA
eduardoAOP2mo ago
sorry but you can see it that is the important part
Want results from more Discord servers?
Add your server