[PYTHON] Visualize the export data of Piyo log

Introduction

Currently, I am using the Piyolog App for raising 0-year-old children. With this app, you can export the content entered on your smartphone as text. I wondered if I could do something with this data.

Purpose

Use the information from the Piyolog app to visualize the growth of your baby based on objective data, and look at the graph saying "Oh! Growing up!" To increase motivation for childcare. (Although I feel that the number of people who get motivated by looking at the graph is limited)

Processing flow

Piyo log → GAS → Raspberry pi (Shell + Python) → LINE When you export from Piyo log and send it to Gmail, the graphed result will be automatically sent to LINE. image.png

Piyo log export format

The text data (one day's worth) exported from the Piyo log looks like this.

piyolog.txt


[Piyo Log] May 2020
2020/5/1(Money)
Child's name(0 years xx months xx days)

02:25 get up(3 hours 15 minutes)
02:30 pee
02:50 sleep
03:50 pee
05:40 get up(2 hours 50 minutes)
05:55 milk 130ml
~ Abbreviation ~
22:45 sleep

Breast milk total left 0 minutes/Right 0 minutes
Milk total 9 times 840ml
Total sleep 13 hours 40 minutes
Pee total 9 times
Poop total 1 time

Contents to be visualized

Make a simple graph so that you can visually understand the trends 1 to 3.

  1. How many ml of milk did you drink at one time in a day?
  2. How much do you drink in a day?
  3. How many ml have you taken in total up to now?

Processing with Raspberry Pi

The code is excerpted only for the main part.

List only necessary items

python


#Piyolog milk,List only items such as poop
def get_piyolog_all_items(texts):
    days = []
    all_items = []

    for month in texts:
        #Split text with line breaks
        lines = month.splitlines()

        #Make it a numpy array
        array = np.array(lines)

        for index, item in enumerate(array):
            #Get date
            if item == "----------" and index < len(array) - 1:
                day = array[index + 1]
                days.append(day)

            #Ignore blank lines & time the item you want to record(hh:mm)Judgment by
            if item != "" and check_item(item):
                #Store date and time and items in an array
                day_items = [day] + item.split()
                all_items.append(day_items)

    return all_items

Calculate maximum / cumulative value of milk

get_each_day_milks


def get_each_day_milks(select, days, all_items):

    for item in all_items:
        #Extract the elements of milk
        if item[2] == "milk":
            milk = item[3]
            milk = int(milk.replace("ml", ""))
            all_milks.append([item[0], item[1], milk])

    for day in days:
        for array_milk in all_milks:

            #Maximum amount of milk per day
            if day == array_milk[0] and day_milk_max < array_milk[2]:
                #Save maximum value once
                tmp_max_milk = array_milk
                #Update the maximum value for the day
                day_milk_max = array_milk[2]

            #Total amount of milk per day
            if day == array_milk[0]:
                day_milk_sum += array_milk[2]

        #0 is not recorded
        if tmp_max_milk != 0:
            #Add to maximum milk list
            max_milks.append(tmp_max_milk)
            #Add to total milk list
            sum_milks.append([day, "", day_milk_sum])
            #Add to cumulative milk list
            all_milk_acc += day_milk_sum
            acc_milks.append([day, "", all_milk_acc])

        #Initialization
        day_milk_max = 0
        day_milk_sum = 0

    # return
    if select == "max":
        return max_milks
    elif select == "sum":
        return sum_milks
    elif select == "acc":
        return acc_milks
    else:
        return "error!"

POST to LINE

python


#Send images to LINE
def send_picture_to_line(PICTURE_PATH):
    url = LINE_URL
    token = LINE_TOKEN
    headers = {"Authorization": "Bearer " + token}

    #message
    payload = {"message": "send picture"}
    #image
    files = {"imageFile": open(PICTURE_PATH, "rb")}
    # post
    requests.post(url, data=payload, headers=headers, files=files)

result

Maximum amount of milk you drank in a day

You can see that the amount of milk you drink increases significantly during the newborn period (0 to 30 days after birth)! Growing up! milk_20200506_144852.png

Changes in the total value of milk drank in one day

After the newborn period, I drink 1000ml almost every day. The reason why the last day has dropped sharply is because it was the data in the middle of the day. milk_20200506_144854.png

Cumulative value of milk you have drank so far

Naturally, it is rising. It may be a natural graph, but moms and dads can feel relieved just by confirming that it is steadily rising. If the slope becomes gentle, are you feeling sick? You may notice. milk_20200506_144855.png

Other

Growth may be seen by visualizing changes in the total sleep time and the average value of sleep time. I am drinking 60000ml = 60000g 80 days after birth. I gained 3500g for my child, so Most of 60000-3500 = 56500g seems to have been peeing and pooping.

Recommended Posts

Visualize the export data of Piyo log
Visualize the orbit of Hayabusa2
Take the execution log of Celery
Memory-saving matrix conversion of log data
Visualize the response status of the census 2020
About Boxplot and Violinplot that visualize the variability of independent data
Explain the mechanism of PEP557 data class
The story of verifying the open data of COVID-19
Visualize the boundary values of the multi-layer perceptron
Get the column list & data list of CASTable
Visualize the effects of deep learning / regularization
Export 3D data from QGIS
Export DB data in json format
Check the data summary in CASTable
Get the column list & data list of CASTable
Data handling
Visualize the export data of Piyo log
Setting to output the log of cron execution
The inaccuracy of Tensorflow was due to log (0)
[Note] Export the html of the site with python.
Visualize the inner layer of a neural network
The story of reading HSPICE data in Python
Visualize the behavior of the sorting algorithm with matplotlib
The transition of baseball as seen from the data
Check the status of your data using pandas_profiling
Download the wind data of the Japan Meteorological Agency
Scraping the winning data of Numbers using Docker
Export access data for each user of Google Analytics.
How to visualize the decision tree model of scikit-learn
Visualize data and understand correlation at the same time
About the inefficiency of data transfer in luigi on-memory
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
Not being aware of the contents of the data in python
Visualize the characteristic vocabulary of a document with D3.js
I tried using the API of the salmon data project
I tried to visualize the spacha information of VTuber
Let's use the open data of "Mamebus" in Python
Visualize the appreciation status of art works with OpenCV
Let's visualize the rainfall data released by Shimane Prefecture
Extract the band information of raster data with python
Visualize the number of complaints from life insurance companies
Numerical summary of data
The beginning of cif2cell
The meaning of self
Visualize data with Streamlit
the zen of Python
Preprocessing of prefecture data
Selection of measurement data
Revenge of the Types: Revenge of types
Try scraping the data of COVID-19 in Tokyo with Python
Use of past weather data 4 (feelings of the weather during the Tokyo Olympics)
A network diagram was created with the data of COVID-19.
Let's utilize the railway data of national land numerical information
Visualize the results of decision trees performed with Python scikit-learn
Let's make the analysis of the Titanic sinking data like that
Analyzing data on the number of corona patients in Japan
How to run the Export function of GCP Datastore automatically
The story of rubyist struggling with python :: Dict data with pycall
Data processing that eliminates the effects of confounding factors (theory)
[Python] I tried to visualize the follow relationship of Twitter
Change the log retention period of CloudWatch Logs in Lambda
Let's visualize the number of people infected with coronavirus with matplotlib
The story of copying data from S3 to Google's TeamDrive
[Python] I tried collecting data using the API of wikipedia
Visualize the flow rate of tweets with Diamond + Graphite + Grafana
What I saw by analyzing the data of the engineer market