<commit_before>#!/usr/bin/python
import pandas as pd
import numpy as np
import matplotlib
import datetime as dt

from matplotlib import pyplot as plt

# Import modules from /batterym/ folder.
import os
import sys
sys.path.append(os.path.abspath('../batterym'))
import log
import smooth
import history


plt.style.use('ggplot')

logs = log.get_battery('../logs/capacity_example')
h = history.History(logs, smoothing=True)
hdata = h.data()

data = pd.DataFrame(hdata)
data = data.rename(columns={'time': 'timestamp'})
data = data.sort_values(by='timestamp', ascending=True)

# Extract charging sessions
data = data[data['status'] == 'Charging']

# Group by sequence_id
# and leave the longest sessions
grouped = data.groupby('sequence_id')['capacity_raw'].size()
grouped = grouped.sort_values(inplace=False, ascending=False)
grouped = grouped[:3]
data = data[data.sequence_id.isin(grouped.index)]
grouped = data.groupby('sequence_id')

fig, ax = plt.subplots()

for name, group in grouped:
    pivot_time = group['timestamp'].max()
    a = abs(group['timestamp'] - pivot_time)
    group['delta_time'] = a
    group = group.sort_values(by='delta_time', ascending=True)
    ax.plot(group['delta_time'], group['capacity_raw'], color='r', marker='x')

ax.set_ylim(0, 101)
# Full screen plot window.
mng = plt.get_current_fig_manager()
mng.resize(*mng.window.maxsize())
# Show plot.
plt.show()
# break


# def draw_round():
#     x = np.linspace(0, 10, 500)
#     y = 10 * np.sin(x)
#     y2 = np.round(y)

#     fig, ax = plt.subplots()

#     ax.set_ylim(-11, 11)
#     ax.plot(x, y, color='b', marker='+')
#     ax.plot(x, y2, color='r', marker='o')

#     # Full screen plot window.
#     mng = plt.get_current_fig_manager()
#     mng.resize(*mng.window.maxsize())

#     # Show plot.
#     plt.show()
<commit_msg>add smoothed curve<commit_after>#!/usr/bin/python
import pandas as pd
import numpy as np
import matplotlib
import datetime as dt

from matplotlib import pyplot as plt

# Import modules from /batterym/ folder.
import os
import sys
sys.path.append(os.path.abspath('../batterym'))
import log
import smooth
import history


plt.style.use('ggplot')

logs = log.get_battery('../logs/capacity_example')
h = history.History(logs, smoothing=True)
hdata = h.data()

data = pd.DataFrame(hdata)
data = data.rename(columns={'time': 'timestamp'})
data = data.sort_values(by='timestamp', ascending=True)

# Extract charging sessions
data = data[data['status'] == 'Charging']

# Group by sequence_id
# and leave the longest sessions
grouped = data.groupby('sequence_id')['capacity_raw'].size()
grouped = grouped.sort_values(inplace=False, ascending=False)
grouped = grouped[:5]
data = data[data.sequence_id.isin(grouped.index)]
grouped = data.groupby('sequence_id')

fig, ax = plt.subplots()

for name, group in grouped:
    pivot_time = group['timestamp'].max()
    delta = group['timestamp'] - pivot_time
    seconds = abs(delta).dt.seconds
    hours = seconds / (60 * 60)
    group['delta_time'] = hours
    group = group.sort_values(by='delta_time', ascending=True)

    print group.head()

    ax.plot(group['delta_time'], group['capacity_raw'], color='r', marker='x')

    x = list(group['delta_time'])
    y = list(group['capacity_raw'])
    x2, y2 = smooth.steps_filter(x, y)
    ax.plot(x2, y2, color='b', marker='o')

ax.set_ylim(0, 101)
# Full screen plot window.
mng = plt.get_current_fig_manager()
mng.resize(*mng.window.maxsize())
# Show plot.
plt.show()
# break


# def draw_round():
#     x = np.linspace(0, 10, 500)
#     y = 10 * np.sin(x)
#     y2 = np.round(y)

#     fig, ax = plt.subplots()

#     ax.set_ylim(-11, 11)
#     ax.plot(x, y, color='b', marker='+')
#     ax.plot(x, y2, color='r', marker='o')

#     # Full screen plot window.
#     mng = plt.get_current_fig_manager()
#     mng.resize(*mng.window.maxsize())

#     # Show plot.
#     plt.show()

{'fraction_non_alphanumeric': 0.162796697626419, 'fraction_numerical': 0.011867905056759546, 'mean_word_length': 4.190093708165997, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5175855', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1388, 'n_words': 316}