{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import firebase_admin as fa\n", "from firebase_admin import credentials\n", "from firebase_admin import firestore as fs\n", "\n", "import csv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "creds = fa.credentials.Certificate('/Users/max/Desktop/ICL-IoT-Weather/data_collector/secrets/icl-iot-weather-firebase-adminsdk.json')\n", "fa.initialize_app(creds)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# UNORDERED DATASET!\n", "# db = fs.client()\n", "# doc_ref = db.collection('weather_data')\n", "# doc = doc_ref.get()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# id_ordered_list = []\n", "# for x in doc:\n", "# id_ordered_list.append(x.id)\n", "# id_ordered_list = id_ordered_list[:1570]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "new_data = []\n", "with open('/Users/max/Desktop/xfile.csv', newline='') as csvfile:\n", " reader= csv.reader(csvfile, delimiter=' ', quotechar='|')\n", " for row in reader:\n", " new_data.append(float(row[0].split(',')[0]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "target = 'local_soil_temperature'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# testdoc = db.collection('weather_data').document(id_ordered_list[0]).get()\n", "# print(testdoc)\n", "# print(testdoc.id)\n", "# print(id_ordered_list[0])\n", "# print(testdoc.id)\n", "# print(testdoc.to_dict())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_ref = db.collection(u'weather_data')\n", "query = data_ref.order_by(u'timestamp', direction=fs.Query.ASCENDING\n", "res = query.get()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "toidl = []\n", "for i in res:\n", " toidl.append(i.id)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "toidl = toidl[:1570]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# here: please, PLEASE check that the database won't be fucked!!!!!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for i in range(len(toidl)):\n", " db.collection('weather_data').document(toidl[i]).update({target: new_data[i]})\n", " # Here goes nothing..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }