# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# Import packages
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#import seaborn as sns
import os
import glob
# %matplotlib inline
#sns.set()

# +
path = r'rnd/2013-8/'                     # use your path
all_files = glob.glob(os.path.join(path, "1*.csv"))     # advisable to use os.path.join as this makes concatenation OS independent

df_from_each_file = (pd.read_csv(f, sep = ';\t') for f in all_files)
concatenated_df   = pd.concat(df_from_each_file)
# -

concatenated_df['Timestamp'] = pd.to_datetime(concatenated_df['Timestamp [ms]'], unit = 's')
concatenated_df.apply(pd.to_numeric, errors='ignore')
concatenated_df.describe()


concatenated_df.head()


# +
#concatenated_df['weekday'] = concatenated_df['Timestamp'].dt.dayofweek
#concatenated_df.tail()
# -

#concatenated_df['weekday'] = concatenated_df['Timestamp'].dt.dayofweek
concatenated_df.set_index('Timestamp',inplace=True)
concatenated_df.tail()

concatenated_df.head()

cpu = concatenated_df[['CPU usage [MHZ]']]
receive = concatenated_df[['Network received throughput [KB/s]']]
transmit = concatenated_df[['Network transmitted throughput [KB/s]']]
concatenated_df.drop('CPU capacity provisioned [MHZ]', axis=1, inplace=True)
concatenated_df.drop('Memory capacity provisioned [KB]', axis=1, inplace=True)
concatenated_df.drop('Timestamp [ms]', axis=1, inplace=True) 
concatenated_df.drop('Memory usage [KB]', axis=1, inplace=True)


concatenated_df.plot(figsize=(20,10), linewidth=5, fontsize=20)
plt.xlabel('Date', fontsize=20);

df_rm = pd.concat([cpu.rolling(12).mean(), receive.rolling(12).mean(), transmit.rolling(12).mean()], axis=1)
df_rm.plot(figsize=(20,10), linewidth=5, fontsize=20)
plt.xlabel('Date', fontsize=20);


# +
def moving_average(series, n):
    """
        Calculate average of last n observations
    """
    return np.average(series[-n:])

moving_average(cpu, 24) # prediction for the last observed day (past 24 hours)
# -

df_rm = pd.concat([diet.rolling(12).mean(), gym.rolling(12).mean()], axis=1)
df_rm.plot(figsize=(20,10), linewidth=5, fontsize=20)
plt.xlabel('Year', fontsize=20);

diet.diff().plot(figsize=(20,10), linewidth=5, fontsize=20)
plt.xlabel('Year', fontsize=20);

StarcoderdataJupyterScriptsDedupFiltered