Skip to content

Instantly share code, notes, and snippets.

@avivl
avivl / cron.yaml
Created February 18, 2018 09:58
Zorya cron
cron:
- description: "Run scheduled tasks"
url: /tasks/schedule
schedule: every 60 minutes synchronized
target: zorya-backend
"""Admin view """
import flask_admin
from flask_admin.contrib import appengine
from wtforms import validators
from collections import OrderedDict
from validators import GreaterEqualThan, SmallerEqualThan
class LastUpdatedOrderedDict(OrderedDict):
"""Store items in the order the keys were last added"""
def calc_slope(self, minuets):
"""
Calculate the slope of available memory change.
:param: minuets how long to go back in time
"""
met = metrics.Metrics(self.cluster_name)
series = met.read_timeseries('YARNMemoryAvailablePercentage', minuets)
retlist = []
def calc_how_many(self):
"""
Calculate how many new nodes of each type we need.
:return:
"""
# No allocated memory so we don't need any workers above the
# bare minimum
if self.scale_to != -1:
self.total = self.min_instances
@app.route('/tasks/check-load')
def check_load():
"""Entry point for cron task that launches a task for each cluster
check cluster stats"""
clusters = settings.get_all_clusters_settings()
for cluster in clusters.iter():
task = taskqueue.add(queue_name='shamash',
url="/monitors",
method='GET',
params={'cluster_name': cluster.Cluster})
@avivl
avivl / cron.yaml
Last active February 4, 2018 06:55
cron:
- description: "check cluster load"
url: /tasks/check-load
schedule: every 2 minutes
def get_tf_record(sentence):
global words
# tokenize the pattern
sentence_words = nltk.word_tokenize(sentence)
# stem each word
sentence_words = [stemmer.stem(word.lower()) for word in sentence_words]
# bag of words
bow = [0]*len(words)
for s in sentence_words:
for i, w in enumerate(words):
# shuffle our features and turn into np.array as tensorflow takes in numpy array
random.shuffle(training)
training = np.array(training)
# trainX contains the Bag of words and train_y contains the label/ category
train_x = list(training[:, 0])
train_y = list(training[:, 1])
# reset underlying graph data
tf.reset_default_graph()
SELECT review ,(communication+price+wait+quality) as score
FROM [[aviv-playground:telegrass_reviews.reviews]
WHERE RAND() < 0.7
city population unique_reviewers ratio
Tel Aviv 438818 3783 0.8620886107680177
Givatayim 58508 424 0.7246872222602038
Bat Yam 128904 761 0.5903618196487308
Ramat Gan 153675 817 0.5316414511143648
Ramat HaSharon 45066 216 0.47929703102116894
Ness Ziona 48161 218 0.4526484084632795
Herzliya 93116 414 0.4446067270930882
Kfar Saba 98981 435 0.43947828371101527
Beersheba 205810 886 0.4304941450852728