{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "id": null,
  "links": [],
  "panels": [
    {
      "gridPos": {
        "h": 3,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 1,
      "options": {
        "content": "### Работа пользователей в RDP\nВерхний блок — завершённый вчерашний день. Средний блок — текущий день. Нижний блок — детализация по сотрудникам и доказанным действиям.",
        "mode": "markdown"
      },
      "title": "Сводка для руководителя",
      "transparent": true,
      "type": "text",
      "fieldConfig": {
        "defaults": {}
      }
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Сколько сотрудников было в активности за вчерашний завершённый день.",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green"
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 0,
        "y": 3
      },
      "id": 2,
      "options": {
        "colorMode": "value",
        "graphMode": "none",
        "justifyMode": "center",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value",
        "noValue": "0"
      },
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -14d)\n  |> filter(fn: (r) => r._measurement == \"aw_rdp_worktime_summary_daily\" and r._field == \"users_count\" and r.host == \"${host}\")\n  |> group(columns:[\"report_date\"])\n  |> last()\n  |> group()\n  |> sort(columns:[\"report_date\"])\n  |> tail(n:2)\n  |> limit(n:1)",
          "refId": "A"
        }
      ],
      "title": "Вчера: сотрудников с активностью",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Суммарное активное время всех пользователей за вчера.",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "decimals": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green"
              }
            ]
          },
          "unit": "suffix: ч"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 6,
        "y": 3
      },
      "id": 3,
      "options": {
        "colorMode": "value",
        "graphMode": "none",
        "justifyMode": "center",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value",
        "noValue": "0"
      },
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -14d)\n  |> filter(fn: (r) => r._measurement == \"aw_rdp_worktime_summary_daily\" and r._field == \"total_active_seconds\" and r.host == \"${host}\")\n  |> group(columns:[\"report_date\"])\n  |> last()\n  |> group()\n  |> sort(columns:[\"report_date\"])\n  |> tail(n:2)\n  |> limit(n:1)\n  |> map(fn:(r)=>({ r with _value: float(v:r._value) / 3600.0 }))\n  |> keep(columns:[\"_value\"])",
          "refId": "A"
        }
      ],
      "title": "Вчера: суммарное активное время",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Среднее активное время на одного сотрудника за вчера.",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "decimals": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green"
              }
            ]
          },
          "unit": "suffix: ч"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 12,
        "y": 3
      },
      "id": 4,
      "options": {
        "colorMode": "value",
        "graphMode": "none",
        "justifyMode": "center",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value",
        "noValue": "0"
      },
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -14d)\n  |> filter(fn: (r) => r._measurement == \"aw_rdp_worktime_summary_daily\" and (r._field == \"users_count\" or r._field == \"total_active_seconds\") and r.host == \"${host}\")\n  |> group(columns:[\"report_date\",\"_field\"])\n  |> last()\n  |> group()\n  |> pivot(rowKey:[\"report_date\"], columnKey:[\"_field\"], valueColumn:\"_value\")\n  |> sort(columns:[\"report_date\"])\n  |> tail(n:2)\n  |> limit(n:1)\n  |> map(fn:(r) => ({ r with _value: float(v: r.total_active_seconds) / float(v: r.users_count) / 3600.0 }))\n  |> keep(columns:[\"_value\"])",
          "refId": "A"
        }
      ],
      "title": "Вчера: среднее время на сотрудника",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Оперативное значение за текущий день. Нормально, если утром оно ещё низкое.",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "decimals": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green"
              }
            ]
          },
          "unit": "suffix: ч"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 18,
        "y": 3
      },
      "id": 5,
      "options": {
        "colorMode": "value",
        "graphMode": "none",
        "justifyMode": "center",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value",
        "noValue": "0"
      },
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -14d)\n  |> filter(fn: (r) => r._measurement == \"aw_rdp_worktime_summary_daily\" and r._field == \"total_active_seconds\" and r.host == \"${host}\")\n  |> group(columns:[\"report_date\"])\n  |> last()\n  |> group()\n  |> sort(columns:[\"report_date\"])\n  |> tail(n:1)\n  |> map(fn:(r)=>({ r with _value: float(v:r._value) / 3600.0 }))\n  |> keep(columns:[\"_value\"])",
          "refId": "A"
        }
      ],
      "title": "Сегодня: накопленное активное время",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Кто сколько реально работал вчера.",
      "fieldConfig": {
        "defaults": {
          "decimals": 1,
          "displayName": "${__field.labels.user}",
          "unit": "suffix: ч"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 7
      },
      "id": 6,
      "options": {
        "colorMode": "value",
        "displayMode": "basic",
        "namePlacement": "left",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showUnfilled": true,
        "sizing": "auto",
        "noValue": "0"
      },
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -14d)\n  |> filter(fn: (r) => r._measurement == \"aw_rdp_worktime_daily\" and r._field == \"active_seconds\" and r.host == \"${host}\")\n  |> group(columns: [\"user\"])\n  |> sort(columns: [\"_time\"])\n  |> tail(n: 2)\n  |> first()\n  |> map(fn: (r) => ({ r with _value: float(v: r._value) / 3600.0 }))",
          "refId": "A"
        }
      ],
      "title": "Вчера: активность по сотрудникам",
      "type": "bargauge"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Накопленное время текущего дня. Это оперативный срез, не итог дня.",
      "fieldConfig": {
        "defaults": {
          "decimals": 1,
          "displayName": "${__field.labels.user}",
          "unit": "suffix: ч"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 7
      },
      "id": 7,
      "options": {
        "colorMode": "value",
        "displayMode": "basic",
        "namePlacement": "left",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showUnfilled": true,
        "sizing": "auto",
        "noValue": "0"
      },
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -3d)\n  |> filter(fn: (r) => r._measurement == \"aw_rdp_worktime_daily\" and r._field == \"active_seconds\" and r.host == \"${host}\")\n  |> group(columns: [\"user\"])\n  |> last()\n  |> filter(fn:(r)=>r._value > 0)\n  |> map(fn: (r) => ({ r with _value: float(v: r._value) / 3600.0 }))",
          "refId": "A"
        }
      ],
      "title": "Сегодня: накопленное время по сотрудникам",
      "type": "bargauge"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Командный итог по дням. Нужен для сравнения нагрузки от дня к дню.",
      "fieldConfig": {
        "defaults": {
          "custom": {
            "drawStyle": "bars",
            "fillOpacity": 80,
            "lineWidth": 1,
            "showPoints": "never"
          },
          "decimals": 1,
          "displayName": "Команда",
          "unit": "suffix: ч"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 15
      },
      "id": 8,
      "options": {
        "legend": {
          "displayMode": "hidden",
          "placement": "bottom",
          "showLegend": false
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -14d)\n  |> filter(fn: (r) => r._measurement == \"aw_rdp_worktime_summary_daily\" and r._field == \"total_active_seconds\" and r.host == \"${host}\")\n  |> group(columns:[\"report_date\"])\n  |> last()\n  |> sort(columns:[\"report_date\"])\n  |> map(fn:(r)=>({ r with _value: float(v:r._value) / 3600.0 }))",
          "refId": "A"
        }
      ],
      "title": "Команда: активное время по дням",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Показывает распределение активности внутри суток по сотрудникам.",
      "fieldConfig": {
        "defaults": {
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "lineWidth": 2,
            "showPoints": "auto"
          },
          "displayName": "${__field.labels.user}",
          "unit": "suffix: ч"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 15
      },
      "id": 9,
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "mode": "multi",
          "sort": "desc"
        }
      },
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -48h)\n  |> filter(fn: (r) => r._measurement == \"aw_rdp_worktime_hourly\" and r._field == \"active_seconds\" and r.host == \"${host}\")\n  |> map(fn: (r) => ({ r with _value: float(v: r._value) / 3600.0 }))\n  |> group(columns: [\"user\"])",
          "refId": "A"
        }
      ],
      "title": "Когда работали в течение суток",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Подробный список по сотрудникам и дням за последнюю неделю.",
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 10,
        "w": 24,
        "x": 0,
        "y": 23
      },
      "id": 10,
      "options": {
        "cellHeight": "sm",
        "footer": {
          "show": false
        },
        "showHeader": true
      },
      "transformations": [
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {
              "Дата": 0,
              "Пользователь": 1,
              "Учётная запись": 2,
              "Часы": 3
            },
            "renameByName": {
              "Учётная запись": "Учётная запись"
            }
          }
        }
      ],
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -14d)\n  |> filter(fn: (r) => r._measurement == \"aw_rdp_worktime_daily\" and r._field == \"active_seconds\" and r.host == \"${host}\")\n  |> group(columns:[\"report_date\",\"user\"])\n  |> last()\n  |> sort(columns:[\"report_date\",\"user\"], desc:true)\n  |> map(fn:(r)=>({ r with _value: float(v:r._value) / 3600.0 }))\n  |> group()\n  |> keep(columns:[\"report_date\",\"user\",\"user_id\",\"_value\"])\n  |> rename(columns:{report_date:\"Дата\", user:\"Пользователь\", user_id:\"Учётная запись\", _value:\"Часы\"})",
          "refId": "A"
        }
      ],
      "title": "Подробно: последние 7 дней по сотрудникам",
      "type": "table"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Строгий показатель: время засчитывается только когда есть foreground window, not-AFK и дополнительное evidence-событие действия пользователя.",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "decimals": 2,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green"
              }
            ]
          },
          "unit": "suffix: ч"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 8,
        "x": 0,
        "y": 33
      },
      "id": 11,
      "options": {
        "colorMode": "value",
        "graphMode": "none",
        "justifyMode": "center",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value",
        "noValue": "0"
      },
      "targets": [
        {
          "query": "import \"date\"\nimport \"strings\"\nimport \"timezone\"\noption location = timezone.location(name: \"Europe/Moscow\")\ntoday = strings.substring(v: string(v: date.add(d: 3h, to: date.truncate(t: now(), unit: 1d))), start: 0, end: 10)\nfrom(bucket: \"aw_metrics\")\n  |> range(start: -3d)\n  |> filter(fn: (r) => r._measurement == \"aw_true_active_app_daily\" and r._field == \"proved_work_seconds\" and r.host == \"${host}\" and r.report_date == today)\n  |> set(key: \"_field\", value: \"Доказанная работа\")\n  |> group(columns:[\"application\"])\n  |> last()\n  |> group()\n  |> sum()\n  |> map(fn:(r)=>({ r with _value: float(v:r._value) / 3600.0 }))\n  |> keep(columns:[\"_value\"])",
          "refId": "A"
        }
      ],
      "title": "Сегодня: доказанная работа по приложениям",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "Приложения, где работа доказана связкой: активная RDP-сессия, не AFK, foreground окно и evidence-событие.",
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Часы"
            },
            "properties": [
              {
                "id": "unit",
                "value": "suffix: ч"
              },
              {
                "id": "decimals",
                "value": 2
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Подтверждений"
            },
            "properties": [
              {
                "id": "decimals",
                "value": 0
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 9,
        "w": 16,
        "x": 8,
        "y": 33
      },
      "id": 12,
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "targets": [
        {
          "query": "import \"date\"\nimport \"strings\"\nimport \"timezone\"\noption location = timezone.location(name: \"Europe/Moscow\")\ntoday = strings.substring(v: string(v: date.add(d: 3h, to: date.truncate(t: now(), unit: 1d))), start: 0, end: 10)\nbase = from(bucket: \"aw_metrics\")\n  |> range(start: -3d)\n  |> filter(fn: (r) => r._measurement == \"aw_true_active_app_daily\" and r.host == \"${host}\" and r.report_date == today)\n\nnums = base\n  |> filter(fn: (r) => r._field == \"proved_work_seconds\" or r._field == \"evidence_events\")\n  |> group(columns:[\"application\",\"_field\"])\n  |> last()\n  |> group()\n  |> pivot(rowKey:[\"application\",\"report_date\"], columnKey:[\"_field\"], valueColumn:\"_value\")\n\ntexts = base\n  |> filter(fn: (r) => r._field == \"last_action\" or r._field == \"last_action_local\")\n  |> group(columns:[\"application\",\"_field\"])\n  |> last()\n  |> group()\n  |> pivot(rowKey:[\"application\",\"report_date\"], columnKey:[\"_field\"], valueColumn:\"_value\")\n\njoin(tables: {n: nums, t: texts}, on: [\"application\", \"report_date\"])\n  |> map(fn:(r)=>({ r with hours: float(v:r.proved_work_seconds) / 3600.0 }))\n  |> sort(columns:[\"proved_work_seconds\"], desc:true)\n  |> group()\n  |> keep(columns:[\"report_date\",\"application\",\"hours\",\"last_action_local\",\"last_action\",\"evidence_events\"])\n  |> rename(columns:{report_date:\"Дата\", application:\"Приложение\", hours:\"Доказано, ч\", last_action_local:\"Последнее действие\", last_action:\"Окно / действие\", evidence_events:\"Подтверждений\"})",
          "refId": "A"
        }
      ],
      "title": "Сегодня: доказанная работа по приложениям - детали",
      "type": "table"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "description": "История доказанной работы по приложениям. Нули означают, что foreground/AFK есть, но нет достаточного evidence действия.",
      "fieldConfig": {
        "defaults": {
          "custom": {
            "drawStyle": "bars",
            "lineInterpolation": "linear",
            "barAlignment": 0,
            "lineWidth": 1,
            "fillOpacity": 35,
            "gradientMode": "none",
            "spanNulls": false,
            "insertNulls": false,
            "showPoints": "never",
            "pointSize": 5,
            "stacking": {
              "mode": "normal",
              "group": "A"
            },
            "axisPlacement": "auto",
            "axisLabel": "",
            "axisColorMode": "text",
            "axisBorderShow": false,
            "scaleDistribution": {
              "type": "linear"
            },
            "hideFrom": {
              "tooltip": false,
              "viz": false,
              "legend": false
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "unit": "suffix: ч",
          "displayName": "${__field.labels.application}"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 42
      },
      "id": 13,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "mode": "multi",
          "sort": "desc"
        }
      },
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -14d)\n  |> filter(fn: (r) => r._measurement == \"aw_true_active_app_daily\" and r._field == \"proved_work_seconds\" and r.host == \"${host}\")\n  |> group(columns:[\"application\",\"report_date\"])\n  |> last()\n  |> map(fn:(r)=>({ r with _value: float(v:r._value) / 3600.0 }))\n  |> set(key: \"_field\", value: \"Доказанная работа\")\n  |> group(columns:[\"application\"])",
          "refId": "A"
        }
      ],
      "title": "Доказанная работа по дням и приложениям",
      "type": "timeseries"
    }
  ],
  "refresh": "10m",
  "schemaVersion": 41,
  "tags": [
    "activitywatch",
    "detmir",
    "management",
    "rdp",
    "worktime"
  ],
  "templating": {
    "list": [
      {
        "current": {
          "selected": false,
          "text": "HOST-EXAMPLE",
          "value": "HOST-EXAMPLE"
        },
        "datasource": {
          "type": "influxdb",
          "uid": "influxdb_aw"
        },
        "definition": "import \"influxdata/influxdb/schema\"\nschema.tagValues(bucket: \"aw_metrics\", tag: \"host\", predicate: (r) => r._measurement == \"aw_rdp_worktime_daily\", start: -30d)",
        "hide": 0,
        "includeAll": false,
        "label": "Хост",
        "multi": false,
        "name": "host",
        "options": [],
        "query": "import \"influxdata/influxdb/schema\"\nschema.tagValues(bucket: \"aw_metrics\", tag: \"host\", predicate: (r) => r._measurement == \"aw_rdp_worktime_daily\", start: -30d)",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-7d",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "browser",
  "title": "DetMir: Работа пользователей в RDP",
  "uid": "detmir-rdp-user-activity",
  "version": 1,
  "weekStart": ""
}
