> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-fbfa8bee.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> دالة تجميع تحسب تنبؤًا خطيًا على غرار PromQL لبيانات السلاسل الزمنية على الشبكة المحددة.

# timeSeriesPredictLinearToGrid

<div id="timeSeriesPredictLinearToGrid">
  ## timeSeriesPredictLinearToGrid
</div>

مُقدَّم في: v25.6.0

دالة تجميعية تأخذ بيانات السلاسل الزمنية على شكل أزواج من الطوابع الزمنية والقيم، وتحسب [تنبؤًا خطيًا مشابهًا لـ PromQL](https://prometheus.io/docs/prometheus/latest/querying/functions/#predict_linear) بإزاحة زمنية محددة للتنبؤ انطلاقًا من هذه البيانات، وذلك على شبكة زمنية منتظمة تُحدَّد بطابع زمني للبداية وطابع زمني للنهاية وخطوة. لكل نقطة على الشبكة، تُؤخذ العينات المستخدمة في حساب `predict_linear` من ضمن النافذة الزمنية المحددة.

<Note>
  هذه الدالة تجريبية. فعِّلها عن طريق ضبط `allow_experimental_ts_to_grid_aggregate_function=true`.
</Note>

**البنية**

```sql theme={null}
timeSeriesPredictLinearToGrid(start_timestamp, end_timestamp, grid_step, staleness, predict_offset)(timestamp, value)
```

**المعاملات**

* `start_timestamp` — يحدّد بداية الشبكة. - `end_timestamp` — يحدّد نهاية الشبكة. - `grid_step` — يحدّد خطوة الشبكة بالثواني. - `staleness` — يحدّد الحد الأقصى لـ "قِدم" العينات التي يُؤخذ بها في الاعتبار، بالثواني. نافذة القِدم هي فترة مفتوحة من اليسار ومغلقة من اليمين. - `predict_offset` — يحدّد عدد ثواني الإزاحة التي ستُضاف إلى وقت التنبؤ.

**الوسيطات**

* `timestamp` — الطابع الزمني للعينة. يمكن أن يكون قيمةً منفردة أو مصفوفة. - `value` — قيمة السلسلة الزمنية المقابلة للطابع الزمني. يمكن أن تكون قيمةً منفردة أو مصفوفة.

**القيمة المُعادة**

قيم `predict_linear` على الشبكة المحددة بوصفها `Array(Nullable(Float64))`. تحتوي المصفوفة المُعادة على قيمة واحدة لكل نقطة زمنية في الشبكة. تكون القيمة NULL إذا لم تكن هناك عينات كافية ضمن النافذة لحساب قيمة المعدل لنقطة شبكة معينة.

**أمثلة**

**احسب قيم predict\_linear على الشبكة \[90, 105, 120, 135, 150, 165, 180, 195, 210] بإزاحة مقدارها 60 ثانية**

```sql title=Query theme={null}
WITH
    -- NOTE: the gap between 140 and 190 is to show how values are filled for ts = 150, 165, 180 according to window parameter
    [110, 120, 130, 140, 190, 200, 210, 220, 230]::Array(DateTime) AS timestamps,
    [1, 1, 3, 4, 5, 5, 8, 12, 13]::Array(Float32) AS values, -- array of values corresponding to timestamps above
    90 AS start_ts,       -- start of timestamp grid
    90 + 120 AS end_ts,   -- end of timestamp grid
    15 AS step_seconds,   -- step of timestamp grid
    45 AS window_seconds, -- "staleness" window
    60 AS predict_offset  -- prediction time offset
SELECT timeSeriesPredictLinearToGrid(start_ts, end_ts, step_seconds, window_seconds, predict_offset)(timestamp, value)
FROM
(
    -- This subquery converts arrays of timestamps and values into rows of `timestamp`, `value`
    SELECT
        arrayJoin(arrayZip(timestamps, values)) AS ts_and_val,
        ts_and_val.1 AS timestamp,
        ts_and_val.2 AS value
);
```

```response title=Response theme={null}
┌─timeSeriesPredictLinearToGrid(start_ts, end_ts, step_seconds, window_seconds, predict_offset)(timestamp, value)─┐
│ [NULL,NULL,1,9.166667,11.6,16.916666,NULL,NULL,16.5]                                                            │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

**نفس الاستعلام مع وسيطات المصفوفة**

```sql title=Query theme={null}
WITH
    [110, 120, 130, 140, 190, 200, 210, 220, 230]::Array(DateTime) AS timestamps,
    [1, 1, 3, 4, 5, 5, 8, 12, 13]::Array(Float32) AS values,
    90 AS start_ts,
    90 + 120 AS end_ts,
    15 AS step_seconds,
    45 AS window_seconds,
    60 AS predict_offset
SELECT timeSeriesPredictLinearToGrid(start_ts, end_ts, step_seconds, window_seconds, predict_offset)(timestamps, values);
```

```response title=Response theme={null}
┌─timeSeriesPredictLinearToGrid(start_ts, end_ts, step_seconds, window_seconds, predict_offset)(timestamp, value)─┐
│ [NULL,NULL,1,9.166667,11.6,16.916666,NULL,NULL,16.5]                                                            │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```
