Last active
          December 25, 2020 23:42 
        
      - 
      
- 
        Save YYx00xZZ/5b404e870b086f5229758e1e10ff8972 to your computer and use it in GitHub Desktop. 
    ulsit-luftdaten
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "nbformat": 4, | |
| "nbformat_minor": 0, | |
| "metadata": { | |
| "colab": { | |
| "name": "ulsit-luftdaten", | |
| "provenance": [], | |
| "collapsed_sections": [], | |
| "toc_visible": true, | |
| "authorship_tag": "ABX9TyP51fk1SALoqPNVxUKTlqUz", | |
| "include_colab_link": true | |
| }, | |
| "kernelspec": { | |
| "name": "python3", | |
| "display_name": "Python 3" | |
| } | |
| }, | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/YYx00xZZ/5b404e870b086f5229758e1e10ff8972/luftdaten.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "metadata": { | |
| "id": "MvGLE8s0b6G2" | |
| }, | |
| "source": [ | |
| "!python -m pip install json_flatten" | |
| ], | |
| "execution_count": null, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "metadata": { | |
| "id": "QnwTvE_ZbV01" | |
| }, | |
| "source": [ | |
| "import json\n", | |
| "import requests\n", | |
| "import pandas as pd\n", | |
| "from json_flatten import flatten as jflatten" | |
| ], | |
| "execution_count": null, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "w_pS6J3Uf9ec" | |
| }, | |
| "source": [ | |
| "# всички измервания за всички сензори за последните 5 минути в `json` формат" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "metadata": { | |
| "id": "GJRdXUIJgZE9" | |
| }, | |
| "source": [ | |
| "# zapazva dannite v promenlivata lastfive_all\n", | |
| "lastfive_all = requests.get('https://data.sensor.community/static/v1/data.json').json()" | |
| ], | |
| "execution_count": null, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "UU6Sse3FhDWo" | |
| }, | |
| "source": [ | |
| "# филтър върху всички измервания от последните 5 минути" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "NFZbMriAkDWP" | |
| }, | |
| "source": [ | |
| "## osnoven adres `https://data.sensor.community/airrohr/v1/filter/{query}`, kudeto `{query}` e kriteriq za filtrirane\n", | |
| "- vuzmojni stoinosti na `{query}` sa:\n", | |
| " - `type={sensor type}` : spisak razdelen sus zapetai za vid senzor, naprimer SDS011,BME280\n", | |
| " - `area={lat,lon,distance}` : vischki senzori v zadadeniq radius (koordinati format DD), naprimer 42.69751 23.32415 (Sofia, Bulgaria)\n", | |
| " - `country={country code}` : spisak sus kodove na stranite koito filtrirame, naprimer BG,BE,DE\n", | |
| " - ??? `box={lat1,lon1,lat2,lon2}` : all sensors in a 'box' with the given coordinates e.g. 52.1,13.0,53.5,13.5\n", | |
| "\n", | |
| " dva i poveche filtura se razdelqt s `?` v url-a, naprimer `type=SDS011?country=BG` - filtrira senzor ot tip __SDS011__ koito se namira v __Bulgaria__" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "SjVS1P_OpF_f" | |
| }, | |
| "source": [ | |
| "## primeri" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "metadata": { | |
| "id": "LaeiPQyHpWzd" | |
| }, | |
| "source": [ | |
| "# za momenta zaqvkata e prazen string, edinstveno za da mojem oshte tuk da\n", | |
| "# definirame osnovniq adres kato formatiran string (python formatted strings)\n", | |
| "query = ''\n", | |
| "\n", | |
| "# osnoven adres\n", | |
| "base_url = f'https://data.sensor.community/airrohr/v1/filter/{query}'" | |
| ], | |
| "execution_count": null, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "wjOs0Wqhv00j" | |
| }, | |
| "source": [ | |
| "### filter po vid senzor" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "pPeL63z3wjLc", | |
| "outputId": "d5b88638-942d-4b9a-f30f-f550dd7072ca" | |
| }, | |
| "source": [ | |
| "# filter po vid senzor\n", | |
| "## samo SDS011 senzori, kachestvo na vazduha\n", | |
| "query = 'type=SDS011'\n", | |
| "base_url = f'https://data.sensor.community/airrohr/v1/filter/{query}'\n", | |
| "print(base_url)\n", | |
| " # https://data.sensor.community/airrohr/v1/filter/type=SDS011\n", | |
| "\n", | |
| "\n", | |
| "## SDS011 i BME280\n", | |
| "query = 'type=SDS011,BME280'\n", | |
| "base_url = f'https://data.sensor.community/airrohr/v1/filter/{query}'\n", | |
| "print(base_url)\n", | |
| " # https://data.sensor.community/airrohr/v1/filter/type=SDS011,BME280" | |
| ], | |
| "execution_count": null, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "text": [ | |
| "https://data.sensor.community/airrohr/v1/filter/type=SDS011\n", | |
| "https://data.sensor.community/airrohr/v1/filter/type=SDS011,BME280\n" | |
| ], | |
| "name": "stdout" | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "XiiUtjNuwQHW" | |
| }, | |
| "source": [ | |
| "### senzori v radius ot koordinati" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "7p6c6Fqlwjun", | |
| "outputId": "52633385-0aa0-4c44-8c4a-ba0cd49c2d1e" | |
| }, | |
| "source": [ | |
| "# senzori v radius koordinati\n", | |
| "## Sofia, 10km radius\n", | |
| "query = 'area=42.69751,23.32415,10'\n", | |
| "base_url = f'https://data.sensor.community/airrohr/v1/filter/{query}'\n", | |
| "print(base_url)\n", | |
| " # https://data.sensor.community/airrohr/v1/filter/area=42.69751,23.32415,10" | |
| ], | |
| "execution_count": null, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "text": [ | |
| "https://data.sensor.community/airrohr/v1/filter/area=42.69751,23.32415,10\n" | |
| ], | |
| "name": "stdout" | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "kHOO3w4Uwa5D" | |
| }, | |
| "source": [ | |
| "### senzori v opredelena strana" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "mYrzLtlcwke4", | |
| "outputId": "cd3d832c-5302-4bbc-f950-50530af547ee" | |
| }, | |
| "source": [ | |
| "# senzori v opredelena strana\n", | |
| "## Germania\n", | |
| "query = 'country=DE'\n", | |
| "base_url = f'https://data.sensor.community/airrohr/v1/filter/{query}'\n", | |
| "print(base_url)\n", | |
| " # https://data.sensor.community/airrohr/v1/filter/country=DE\n", | |
| "\n", | |
| "\n", | |
| "## Bulgaria i Germania\n", | |
| "query = 'country=BG,DE'\n", | |
| "base_url = f'https://data.sensor.community/airrohr/v1/filter/{query}'\n", | |
| "print(base_url)\n", | |
| " # https://data.sensor.community/airrohr/v1/filter/country=BG,DE" | |
| ], | |
| "execution_count": null, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "text": [ | |
| "https://data.sensor.community/airrohr/v1/filter/country=DE\n", | |
| "https://data.sensor.community/airrohr/v1/filter/country=BG,DE\n" | |
| ], | |
| "name": "stdout" | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "RuT_pCKyweqe" | |
| }, | |
| "source": [ | |
| "### filtrirane po mnogo kriterii" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "6u4d2sckwlGQ", | |
| "outputId": "3b90138a-2300-4cb8-e132-c49dbff4d889" | |
| }, | |
| "source": [ | |
| "# filtrirane po mnogo kriterii\n", | |
| "## SDS011 senzori namirashti se v Bulgaria\n", | |
| "query = 'type=SDS011?country=BG'\n", | |
| "base_url = f'https://data.sensor.community/airrohr/v1/filter/{query}'\n", | |
| "print(base_url)\n", | |
| " # https://data.sensor.community/airrohr/v1/filter/type=SDS011?country=BG" | |
| ], | |
| "execution_count": null, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "text": [ | |
| "https://data.sensor.community/airrohr/v1/filter/type=SDS011?country=BG\n" | |
| ], | |
| "name": "stdout" | |
| } | |
| ] | |
| } | |
| ] | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment