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

# + [markdown] id="oC0qpliGxcrU"
#

# + id="N0XTJFQXmsbb"
from google.colab import drive
drive.mount('/content/gdrive',force_remount=True)

# + id="3055c1p_x4wH"
# !pip install numba

# + id="HkyZ6vAApMdk"
import os
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from numba import jit
PATH = 'gdrive/My Drive/VSUMM/ydata-tvsum50-v1_1/'
os.listdir(PATH)

# + id="jqflMn1jriIy"
# Descomprimir los archivos
os.system('unzip '+ PATH + '/ydata-tvsum50-data.zip')
os.system('unzip '+ PATH + '/ydata-tvsum50-thumbnail.zip')

# + id="YuMX9JSLuY8X"

info = pd.read_csv(PATH+'/data/ydata-tvsum50-info.tsv', sep='\t')
info.category = pd.Categorical(info.category)
info.head()

# + id="4zl2TKZmv78k"
info.info()

# + id="CcM6XcwawEm4"
#Convert length in float
info['minute'] = pd.to_datetime(info.length, format='%M:%S').dt.minute
info['second'] = pd.to_datetime(info.length, format='%M:%S').dt.second

# + id="ipKw-41tyX5r"
info.describe()

# + id="sq1hyTEku2X1"
sns.histplot(data=info, x='minute', kde=True)

# + [markdown] id="RzYVXvWe03Zh"
# la mayoría de los videos duran dos minutos

# + id="qiNkpdRE0ZYW"
sns.histplot(data=info, x='second',kde=True)

# + [markdown] id="tkcon5TA1Dfb"
# En su mayoría duran 20 segundos

# + id="xE5Lyu-H0y_e"
sns.histplot(data=info, x='category',kde=True)

# + [markdown] id="pfJVRqw_1JjX"
# Es igual para todas las categorías.

# + id="2TBNiWBc1Xbi"
g = sns.scatterplot(data=info, x=info.index, y=info.second)
plt.title("Second vs Index")
plt.xlabel("Index")


# + id="OsBfz6Mj1zyC"
g = sns.scatterplot(data=info, x=info.index, y=info.minute)
plt.title("minute vs Index")
plt.xlabel("Index")

# + id="cdhVF8UT2sIz"
g = sns.violinplot(x="category",
            y="minute",
            data=info)
plt.title('Boxplot por cada categoria del video')


# + id="ynEtPY6W30WY"
df_query = info.groupby('category')['minute', 'second'].mean()
g=sns.stripplot(x=df_query.index, y='minute', data=df_query)
plt.title('promedio de minutos de duración de cada tipo de video')

# + id="ouqZ6NVb5vRs"
g=sns.stripplot(x=info.category, y='minute', data=info)
plt.title('Total de minutos de cada tipo de video')

# + [markdown] id="mjuqMi3Z6OjG"
# La categoría Bt, en promedio dura muy poco
#
#

# + id="W02j2hKs7sCb"
g = sns.violinplot(x="category",
            y="second",
            data=info)
plt.title('Boxplot por cada categoria del video')


# + id="TiL_shtZ7Glw"
g=sns.stripplot(x=df_query.index, y='second', data=df_query)
plt.title('promedio de segundos de duración de cada tipo de video')

# + id="O1Y2OpoB7TNx"
g=sns.stripplot(x=info.category, y='second', data=info)
plt.title('Total de segudos de cada tipo de video')

# + id="qFexHDq_7eSZ"
sns.stripplot(x='minute', y='second', hue='category', data=info, dodge=True)

# + id="Xp-yqX7R9D_B"

anno = pd.read_csv(PATH+'/data/ydata-tvsum50-anno.tsv', delimiter='\t', names=['id', 'category', 'score'])
anno.category = pd.Categorical(anno.category)
anno.head()


# + id="iZlmaGd3yG48"
#prueba de rachas
@jit
def count_racha(array):
  racha = 0

  for i in range(array.shape[0]):
    if array[i-1] != array[i]:
      racha += 1
  return racha

def racha(str_num):
  hold_score = 3
  array = np.array(str_num.split(','), dtype=int)
  good_score = array[array>=hold_score]

  total_racha = count_racha(array) 
  racha = count_racha(good_score)
  return racha/total_racha


def percetaje(str_num):
  array = np.array(str_num.split(','), dtype=int)
  good_score = array[array>=3]
  return good_score.shape[0]/array.shape[0]
  
  



# + id="alLB-lyPyMfc"
anno['frecuency_score_growth_4'] = anno.score.apply(lambda x: racha(x))

# + [markdown] id="hKXhVis21-LT"
#

# + id="jwR6tUqJ7aOF"
anno.frecuency_score_growth_4.plot()

# + id="oJ-IWP658McS"
anno.frecuency_score_growth_4.describe()

# + id="_wa6WeW_-Wx5"
anno.groupby('category')['frecuency_score_growth_4'].describe()

# + id="b45x54IA9Ppu"
sns.lineplot(x=anno.index, y="frecuency_score_growth_4", hue="category", data =anno)

# + id="5adCKii6_tO0"
prueba = np.array(anno.score.iloc[0].split(','), dtype=int)
index = np.where(prueba>=4)[0] * 2 #time in seconds
plot = pd.DataFrame(index, columns=['seconds'])
sns.lineplot(x=plot.index, y=plot.seconds)


# + id="XG7J-ucn2TSJ"
anno['per'] = anno.score.apply(lambda x: percetaje(x))

# + id="0bTvFKcm3cr2"
anno.groupby('category')['per'].describe()

# + id="KV85W2Xh3ou-"
sns.lineplot(x=anno.index, y="per", hue="category", data =anno)

# + id="CuOxZJOy48Q9"
sns.histplot(data=anno, x='per')

# + id="SXyK71qw5tDI"
sns.boxplot(data=anno)

# + id="VvPuQ5kZ5lEL"
sns.boxplot(x="category", y="per", data=anno)

# + id="VedqkCCu5CbM"
sns.histplot(data=anno, x='frecuency_score_growth_4')

# + id="eHSqz1H35140"
sns.boxplot(x="category", y="frecuency_score_growth_4", data=anno)

StarcoderdataJupyterScriptsDedupFiltered