Skip to content

Instantly share code, notes, and snippets.

View rvipandey's full-sized avatar

Ravi Pandey rvipandey

View GitHub Profile
def speakerdiarisationdf(hyp, frameRate, wavFile):
audioname=[]
starttime=[]
endtime=[]
speakerlabel=[]
spkrChangePoints = np.where(hyp[:-1] != hyp[1:])[0]
if spkrChangePoints[0]!=0 and hyp[0]!=-1:
spkrChangePoints = np.concatenate(([0],spkrChangePoints))
spkrLabels = []
xdata = np.array(list(abs(fmodel.day_count)))
ydata = np.array(list(abs(fmodel.Confirmed)))
cof,cov = curve_fit(sigmoid, xdata, ydata, method='trf',bounds=([0.,0., 0.],[indiapopulation,1, 100.]))
#‘trf’ : Trust Region Reflective algorithm, particularly suitable for large sparse problems with bounds. Generally robust method.
x = np.linspace(-1, fmodel.day_count.max()+40, 40)
y = sigmoid(x,cof[0],cof[1],cof[2])
fig = go.Figure()
indiapopulation=1380004385
fmodel=population[population.Confirmed>=50]
fmodel['day_count']=list(range(1,len(fmodel)+1))
fmodel['increase'] = (fmodel.Confirmed-fmodel.Confirmed.shift(1)).fillna(0).astype(int)
fmodel['increaserate']=(fmodel['increase']/fmodel["Confirmed"])
fmodel['Active']=fmodel['Confirmed']-fmodel['Deceased']-fmodel['Recovered']
xdata = np.array(list(abs(fmodel.day_count)))
ydata = np.array(list(abs(fmodel.Active)))
cof,cov = curve_fit(sigmoid, xdata, ydata, method='trf',bounds=([0.,0., 0.],[indiapopulation,1, 100.]))
def sigmoid(x,c,a,b):
y = c*1 / (1 + np.exp(-a*(x-b)))
return y
population=state_wise_daily.groupby(["Date"])[["Confirmed","Deceased","Recovered"]].sum().reset_index()
population["day_count"]=list(range(1,len(population)+1))
fig = px.bar(population, x='day_count', y='Confirmed',text='Confirmed')
fig.update_traces(texttemplate='%{text:.2s}', textposition='outside')
fig.update_layout(
xaxis_title="Day",
yaxis_title="Population Effected",
title='Evaluation of Confirmed Cases In India',template='gridon')
fig.show()
stanalysis("Gujarat",'Recovered')
stanalysis("Madhya Pradesh",'Recovered')
stanalysis("West Bengal",'Recovered')
def stanalysis(statename,typ):
definestate=state_wise_daily[state_wise_daily.State_Name==statename]
finalstate= definestate.groupby(["Date","State_Name"])[["Confirmed","Deceased","Recovered"]].sum().reset_index().reset_index(drop=True)
createfigure(finalstate,typ,statename)
def createfigure(dataframe,typ,statename):
fig = go.Figure()
fig.add_trace(go.Scatter(x=dataframe["Date"], y=dataframe["Confirmed"],
mode="lines+text",
name='Confirmed',
state_wise=state_wise_daily.groupby("State_Name").sum().reset_index()
state_wise["Mortality Rate Per 100"] =np.round(100*state_wise["Deceased"]/state_wise["Confirmed"],2)
state_wise['Mortality Rate Per 100'] = state_wise['Mortality Rate Per 100'].fillna(0)
state_wise.sort_values(by='Mortality Rate Per 100',ascending=False).style.background_gradient(cmap='Blues',subset=["Confirmed"])\
.background_gradient(cmap='Greens',subset=["Recovered"])\
.background_gradient(cmap='Reds',subset=["Deceased"])\
.background_gradient(cmap='YlOrBr',subset=["Mortality Rate Per 100"]).hide_index()
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import plotly.express as px
pd.set_option('display.max_rows', None)
import datetime
from plotly.subplots import make_subplots
from scipy.optimize import curve_fit
import warnings