Skip to content

Commit

Permalink
Removed the 4 terms limit for OpnInsights
Browse files Browse the repository at this point in the history
  • Loading branch information
anuran-roy committed Jul 9, 2021
1 parent 71f0694 commit f2bcc88
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
Binary file modified OpnInsights/scripts/__pycache__/trends.cpython-38.pyc
Binary file not shown.
42 changes: 30 additions & 12 deletions OpnInsights/scripts/trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,45 @@
# import seaborn as sns
import plotly
# import kaleido
print("Setup complete")
import time
# print("Setup complete")

class Trends:

def getTrend(self, text):
text = text.replace(r"\r\n", "\n")
terms = text.split("\n")
trend = tr(hl="en-US", tz=30)
trend.build_payload(kw_list=terms)
i = 0
br = []
while(i<len(terms)):
br.append(terms[i:i+4])
i+=4
try:
df = pd.DataFrame()
dft = pd.DataFrame()
for i in range(len(br)):
trend = tr(hl="en-US", tz=365)
trend.build_payload(kw_list=br[i])
dft = trend.interest_over_time()
dft = dft.drop("isPartial", axis=1)
# print("DFT=\n",dft)
if i == 0:
df = dft.copy()
else:
df = pd.concat([df, dft], axis = 1)
# print("DF=\n",df)
time.sleep(2)

col = list(df.columns)

df = trend.interest_over_time()
df["date"] = df.index
pt = px.line(df, x=df.index, y = col)# ["Data Science", "Web Development", "Ethical Hacking", "Cybersecurity"])
# pt.show()
fig = plotly.offline.plot(pt, include_plotlyjs=True, output_type='div')

col = list(df.columns)
col.remove("date")
col.remove("isPartial")
col
pt = px.line(df, x="date", y = col)
fig = plotly.offline.plot(pt, include_plotlyjs=True, output_type='div')
return [fig, df]

return [fig, df]
except Exception as e:
return [f"<h1>An error was encountered. Error log: {e}</h1>", None]

def execute(text):
ob = Trends()
Expand Down
2 changes: 1 addition & 1 deletion templates/OpnEmo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ <h1 align="center" style="padding:3%;color:#04AA6D;font-family: 'Bona Nova', ser
<label for="floatingInput">Text:</label> -->
<!-- <br> -->
<textarea class="form-control" placeholder="Leave a comment here" id="floatingTextarea2" name="toAnalyze" style="height:400px; width: 100%; border-radius:0%;background-color: #303030;color:white"></textarea>
<label for="floatingTextarea2">Enter Text:</label>
<label for="floatingTextarea2">Enter the terms:</label>
<br>
<br>
<center><button type="submit" class="btn btn-outline-success" style="width:200px;height:80px;font-size:x-large;">Submit</button></center>
Expand Down

0 comments on commit f2bcc88

Please sign in to comment.