> For the complete documentation index, see [llms.txt](https://docs.mluvii.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mluvii.com/pro-it-specialisty/realtime-statistiky/ukazkove-kody.md).

# Ukázkové kódy

## Ukázka kódu pro připojení pomocí C sharp

Stáhneme nuget package pro práci s influxem: <https://www.nuget.org/packages/InfluxDB.Client/>

Po naimportování nuget knihovny do projektu se do databáze připojíme pomocí následujícího kódu:

```
var influxDBClient = InfluxDBClientFactory.Create(url, token);
```

* Url a token získáme pomocí kroků v připojení.

Pro dotazování do databáze se používá skriptovací jazyk [flux](https://docs.influxdata.com/influxdb/v2.0/query-data/get-started/).

Ukázka dotazu pro získání dat ohledně běžících sezení:

```
private static async Task<List<FluxTable>> GetFluxTables(int companyId, string measurement)
{
    var flux = "from(bucket:\"mluvii_realtime\") " +
               "|> range(start: -1h)" +
              $"|> filter(fn: (r) => r[\"_measurement\"] == \"{measurement}\")" +
               "|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")";
     return await influxDBClient.GetQueryApi().QueryAsync(flux, org: $"company_{companyId}");
}
```

* Bucket je vždycky stejný, tedy "mluvii\_realtime"
* CompanyId je id společnosti
* Measurement je kombinace jména metriky a suffixu v nastavení metrik v mluvii.&#x20;

{% hint style="info" %}
*Příklad: running\_sessions\_demo, kde "running\_sessions" je název metriky a "demo" je nastaveno v mluvii*
{% endhint %}

### Kam dál?

* [Zobrazení dat v Grafaně](/pro-it-specialisty/realtime-statistiky/grafana.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mluvii.com/pro-it-specialisty/realtime-statistiky/ukazkove-kody.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
