-1
JavaScriptに慣れていない私は、サーバーフレームワークとしてNodeJを、アプリケーションフレームワークとしてAngularJを持つWebアプリケーションに取り組んでいます。私はビュー/テンプレートにグラフ(matplotlib)を表示するpythonスクリプトを実行したいと思います。ここにpythonコードがあります。 mongodbサーバからデータを取得するプロセスは、NodeJsコントローラで行うことができます。AngularJsのPythonスクリプト
# In[2]:
import pymongo
import json
import datetime as dt
from pymongo import MongoClient
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
import numpy as np
# In[77]:
l=['ts','cd']
df = pd.DataFrame(columns=l)
k=0
if __name__ == '__main__':
client = MongoClient("localhost", 27017, maxPoolSize=50)
db=client.test
collection=db['data']
cursor = collection.find({"dId":3},{"ts":1,"cd":1}).sort("ts",-1).limit(25000)
for document in cursor:
df.loc[k,'ts']=document.values()[1]
df.loc[k,'cd']=document.values()[2]
k=k+1
# In[78]:
times = pd.DataFrame(pd.to_datetime(df.ts))
# In[79]:
times['hour']=times['ts'].dt.hour
times['date']=times['ts'].dt.date
times['weekday']=times['ts'].dt.weekday
# In[80]:
grouped = pd.DataFrame(columns=['date','hour','weekday','count'])
grouped[['date','hour','weekday','count']] = times.groupby(['date','hour','weekday']).count().reset_index()
# In[81]:
irregularities=grouped[grouped['count'] != 60][['date','hour','weekday','count']]
# In[82]:
get_ipython().magic(u'matplotlib inline')
x = irregularities['weekday']
plt.hist(x, bins=30)
plt.ylabel('Count of irregularities')
plt.xlabel('day of week')
plt.xticks([0,1,2,3,4,5,6],['mon','tue','wed','thurs','fri','sat','sun'])
# In[86]:
x = irregularities['hour']
plt.hist(x, bins=30)
plt.ylabel('Count of irregularities')
plt.xlabel('Hour of day')
私はこのPythonスクリプトをAngular Jsに統合する方法を理解できません。どうやってやるの?
はあなたの助けをありがとう必要なほぼ正確に何をしmpld3ライブラリがあります! –