-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from artemis-beta/teleplot
Teleplot v0.1.0
- Loading branch information
Showing
4 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import matplotlib.pyplot as plt | ||
from uuid import uuid4 | ||
|
||
|
||
class TelePlot: | ||
def __init__(self, x, y, plot_type='scatter', style='default'): | ||
self.plotType = plot_type | ||
self.plotStyle = style | ||
self.xlabel = 'x' | ||
self.ylabel = 'y' | ||
self.x = x | ||
self.y = y | ||
|
||
def parseOpts(self, in_array): | ||
for opts_tuple in in_array: | ||
if 'xaxis' in opts_tuple[0]: | ||
print("Got Axis title for x of " + opts_tuple[1]) | ||
self.xlabel = opts_tuple[1] | ||
if 'yaxis' in opts_tuple[0]: | ||
self.ylabel = opts_tuple[1] | ||
plt.xlabel(self.xlabel) | ||
plt.ylabel(self.ylabel) | ||
plt.plot(self.x,self.y) | ||
filename = './{}.png'.format(str(uuid4())[:6]) | ||
plt.savefig(filename) | ||
return filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#show spacecats test plugin | ||
# Adapted from work by LanceMaverick | ||
import telepot | ||
import telepot.aio | ||
from skybeard.beards import BeardChatHandler | ||
from skybeard.predicates import regex_predicate | ||
from skybeard.decorators import onerror | ||
from skybeard.utils import get_args | ||
from . import TelePlot | ||
import re | ||
import os | ||
import sympy as sp | ||
from numpy import linspace | ||
from math import * | ||
|
||
def format_msg(msg): | ||
text = msg['text'] | ||
return ' '.join(get_args(text)).title() | ||
|
||
|
||
class NationalRailDepartures(BeardChatHandler): | ||
__userhelp__ = """ | ||
The following commands are available: | ||
""" | ||
|
||
__commands__ = [ | ||
("teleplot", "makePlot", "Make plot from two arrays.\n`\\teleplot [x1,x2,..,xN] [y1,y2,..,yN]`\n`\\teleplot (x**2+2*x+3)`\nAdditional options: `-xaxis \"label\"`, `-yaxis \"label\"`\n Currently only index, add, subtract, divide, multiply available for equation notation."), | ||
] | ||
|
||
@onerror | ||
async def makePlot(self, msg): | ||
in_string = msg['text'].replace('/teleplot ', '') | ||
arrays = re.findall(r'(\[[\-\d\,\.\s]+\])+', in_string) | ||
|
||
options = re.findall(r'\-(\w+)\s\"([\w\d\s\.\-\'\)\(\,]+)', in_string) | ||
|
||
print("options: ") | ||
print(options) | ||
if len(arrays) < 1: | ||
eqn = re.findall(r'(\([\w\(\)\d\s\-\+\*\/]+\))', in_string) | ||
eqn = eqn[0] | ||
X = linspace(-10, 10, 100) | ||
Y = [] | ||
for i in X: | ||
equation = eqn.replace('x','{}'.format(i)).replace('(','').replace(')','') | ||
j = sp.simplify(equation) | ||
Y.append(j) | ||
|
||
else: | ||
print("Arrays: ") | ||
assert len(arrays) == 2, "Error: Insufficient Number of Arrays Given." | ||
X = re.findall(r'([\d\.\-]+)', arrays[0]) | ||
Y = re.findall(r'([\d\.\-]+)', arrays[1]) | ||
print(X,Y) | ||
content_type, chat_type, chat_id = telepot.glance(msg) | ||
|
||
plotter = TelePlot.TelePlot(X, Y) | ||
file_name = plotter.parseOpts(options) | ||
await self.sender.sendPhoto(('temp.png', open('{}'.format(file_name), 'rb'))) | ||
os.remove('{}'.format(file_name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bs4==0.0.1 | ||
sympy==0.7.6.1 | ||
numpy==1.11.0 | ||
matplotlib==1.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,3 @@ urllib3==1.19.1 | |
yarl==0.8.1 | ||
pyconfig==3.1.1 | ||
dataset==0.7.0 | ||
|