Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sunrise and sunset examples incorrect? #3

Open
kenfehling opened this issue Jan 24, 2024 · 4 comments
Open

Sunrise and sunset examples incorrect? #3

kenfehling opened this issue Jan 24, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@kenfehling
Copy link

kenfehling commented Jan 24, 2024

Maybe I'm doing something wrong, but I've been having trouble using sunrise and sunset with the TypeScript SDK. I figured a way to make it work; not sure if this is the right way of doing it. If so, I think it'd be useful to update the example code.

Steps to Reproduce the Problem

Use the example TypeScript code from the docs/demo site

sunrise: daily.variables(0)!.valuesArray()!

Fix

Instead, I got this code to work with a hint from the SDK schema docs

sunrise: Number(daily.variables(0)!.valuesInt64(0))

Environment

  • Version: 1.1.3
  • Platform: Mac
  • Node.js Version: 18
@kenfehling kenfehling added the bug Something isn't working label Jan 24, 2024
@patrick-zippenfenig
Copy link
Member

Hi, thanks for the report. Yes, the demo code generator on the API documentation does not select the right array for sunrise and sunset. The ideal code would be daily.variables(0)!.valuesInt64Array()!

@kenfehling
Copy link
Author

Thanks! Oh I see, yeah I'm only fetching for one day but I can see how it'd be useful to fetch an array if you're fetching forecasts for multiple days. It doesn't seem like valuesInt64Array exists though, I only have these:

export declare class VariableWithValues {
    bb: flatbuffers.ByteBuffer | null;
    bb_pos: number;
    __init(i: number, bb: flatbuffers.ByteBuffer): VariableWithValues;
    static getRootAsVariableWithValues(bb: flatbuffers.ByteBuffer, obj?: VariableWithValues): VariableWithValues;
    static getSizePrefixedRootAsVariableWithValues(bb: flatbuffers.ByteBuffer, obj?: VariableWithValues): VariableWithValues;
    variable(): Variable;
    unit(): Unit;
    value(): number;
    values(index: number): number | null;
    valuesLength(): number;
    valuesArray(): Float32Array | null;
    valuesInt64(index: number): bigint | null;
    valuesInt64Length(): number;
    altitude(): number;
    aggregation(): Aggregation;
    pressureLevel(): number;
    depth(): number;
    depthTo(): number;
    ensembleMember(): number;
}

@beaugunderson
Copy link

beaugunderson commented Sep 9, 2024

looks like the demo code generator is still broken, can't figure out how to get sunrise/sunset out... tried this:

    sunrise: daily.variables(2)!.valuesInt64(0)!,
    sunset: daily.variables(3)!.valuesInt64(0)!,

but no joy, I also can't access valuesInt64Array

@beaugunderson
Copy link

beaugunderson commented Sep 9, 2024

ended up using this for them:

function sunToArray(index: number) {
  const array: bigint[] = [];
  const count = daily.variables(index)?.valuesInt64Length() as number;

  for (let i = 0; i < count; i++) {
    array.push(daily.variables(index)?.valuesInt64(i) as bigint);
  }

  return array;
}

and then in daily:

    sunrise: sunToArray(2),
    sunset: sunToArray(3),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants