{
  "annotations": {
    "list": []
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 27,
  "links": [],
  "panels": [
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "fieldConfig": {
        "defaults": {
          "decimals": 0,
          "unit": "suffix: мин",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green"
              },
              {
                "color": "yellow",
                "value": 120
              },
              {
                "color": "red",
                "value": 360
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 0,
        "y": 0
      },
      "id": 5,
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -24h)\n  |> filter(fn: (r) => r._measurement == \"aw_worktime_exporter_heartbeat\" and r._field == \"run\")\n  |> last()\n  |> group()\n  |> sort(columns: [\"_time\"], desc: true)\n  |> limit(n: 1)\n  |> map(fn: (r) => ({ r with _value: (float(v: uint(v: now()) - uint(v: r._time)) / 1000000000.0) / 60.0 }))\n  |> set(key: \"_field\", value: \"Свежесть\")\n  |> keep(columns: [\"_value\", \"_field\"])\n  |> yield(name: \"freshness_minutes\")\n",
          "refId": "A"
        }
      ],
      "title": "Свежесть worktime данных",
      "type": "stat",
      "options": {
        "colorMode": "value",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value",
        "noValue": "0"
      }
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "fieldConfig": {
        "defaults": {
          "decimals": 1,
          "unit": "suffix: ч",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green"
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 6,
        "y": 0
      },
      "id": 4,
      "targets": [
        {
          "query": "from(bucket: \"aw_metrics\")\n  |> range(start: -3d)\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\"])\n  |> yield(name: \"total_today_hours\")\n",
          "refId": "A"
        }
      ],
      "title": "Сегодня: активное время",
      "type": "stat",
      "options": {
        "colorMode": "value",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "value",
        "noValue": "0"
      }
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "suffix: ч",
          "displayName": "${__field.labels.user}"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 0
      },
      "id": 1,
      "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  |> set(key: \"_field\", value: \"Активность, ч\")\n  |> group(columns: [\"user\"])\n  |> yield(name: \"hourly_active_hours\")\n",
          "refId": "A"
        }
      ],
      "title": "Активность RDP по часам",
      "type": "timeseries",
      "options": {
        "legend": {
          "displayMode": "table",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "mode": "multi",
          "sort": "desc"
        }
      }
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "fieldConfig": {
        "defaults": {
          "decimals": 1,
          "unit": "suffix: ч",
          "displayName": "${__field.labels.user}"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 4
      },
      "id": 2,
      "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 }))\n  |> set(key: \"_field\", value: \"Часы\")\n  |> yield(name: \"today_user_hours\")\n",
          "refId": "A"
        }
      ],
      "title": "Сегодня: активность по сотрудникам",
      "type": "bargauge",
      "options": {
        "displayMode": "gradient",
        "minVizWidth": 8,
        "minVizHeight": 16,
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showUnfilled": true,
        "valueMode": "color"
      }
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "fieldConfig": {
        "defaults": {
          "decimals": 2,
          "unit": "suffix: ч",
          "displayName": "${__field.labels.application}"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 8
      },
      "id": 3,
      "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  |> group(columns: [\"application\"])\n  |> last()\n  |> map(fn: (r) => ({ r with _value: float(v: r._value) / 3600.0 }))\n  |> set(key: \"_field\", value: \"Доказано, ч\")\n  |> sort(columns: [\"_value\"], desc: true)\n  |> yield(name: \"apps_today_hours\")\n",
          "refId": "A"
        }
      ],
      "title": "Сегодня: доказанная работа по приложениям",
      "type": "barchart",
      "options": {
        "legend": {
          "displayMode": "table",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "mode": "single",
          "sort": "desc"
        }
      }
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "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": 12
      },
      "id": 6,
      "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 }))\n  |> set(key: \"_field\", value: \"Команда, ч\")\n  |> yield(name: \"team_daily_hours\")\n",
          "refId": "A"
        }
      ],
      "title": "Команда: активное время по дням",
      "type": "timeseries",
      "options": {
        "legend": {
          "displayMode": "table",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "mode": "multi",
          "sort": "desc"
        }
      }
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "influxdb_aw"
      },
      "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": 10,
        "w": 24,
        "x": 0,
        "y": 20
      },
      "id": 7,
      "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:\"Подтверждений\"})\n",
          "refId": "A"
        }
      ],
      "title": "Сегодня: приложения и подтверждения",
      "type": "table"
    }
  ],
  "refresh": "5m",
  "schemaVersion": 41,
  "style": "dark",
  "tags": [
    "detmir",
    "activitywatch"
  ],
  "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-48h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "DetMir ActivityWatch",
  "uid": "detmir-aw-main",
  "version": 4,
  "weekStart": ""
}
