楼主: Lisrelchen
1107 3

【GitHub】Pyleus [推广有奖]

  • 0关注
  • 62粉丝

VIP

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
49957 个
通用积分
79.5487
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
Pyleus

Pyleus is a Python 2.6+ framework for developing and launching Apache Storm topologies.

Please visit our documentation.

masterdevelop
About

Pyleus is a framework for building Apache Storm topologies in idiomatic Python.

With Pyleus you can:

  • define a topology with a simple YAML file
  • have dependency management with a requirements.txt file
  • run faster thanks to Pyleus’ MessagePack based serializer
  • pass options to your components directly from the YAML file
  • use the Kafka spout built into Storm with only a YAML change

本帖隐藏的内容

pyleus-develop.zip (123.7 KB)



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:GitHub Hub Requirements Requirement Developing management framework building directly simple

沙发
Lisrelchen 发表于 2017-3-24 08:29:53 |只看作者 |坛友微信交流群
  1. from __future__ import absolute_import

  2. from array import array
  3. from collections import defaultdict
  4. import logging
  5. import time

  6. from pyleus.storm import SimpleBolt

  7. from apparent_temperature.measure_generator import Measure

  8. log = logging.getLogger('heat_index_bolt')

  9. CX = (
  10.     -42.379,
  11.     2.04901523,
  12.     10.14333127,
  13.     -0.22475541,
  14.     -6.83783 * 0.001,
  15.     -5.481717 * 0.01,
  16.     1.22874 * 0.001,
  17.     8.5282 * pow(10, -4),
  18.     -1.99 * pow(10, -6))


  19. def _heat_index(temp, hum):
  20.     temp2 = temp * temp
  21.     hum2 = hum * hum
  22.     factors = (1, temp, hum, temp * hum, temp2, hum2, temp2 * hum, temp * hum2,
  23.                temp2 * hum2)
  24.     heat = 0
  25.     for idx in range(len(CX)):
  26.         heat += CX[idx] * factors[idx]
  27.     return round(heat, 2)


  28. class HeatIndexBolt(SimpleBolt):

  29.     def initialize(self):
  30.         # The two measures to be joined will be stored togheter in an array,
  31.         # where the inf value means that the measure is missing
  32.         default = lambda: array('f', [float('inf')] * 2)

  33.         # The array will be stored in a dictionary using as key the sensor_id
  34.         # which produced the measures
  35.         self.join = defaultdict(default)

  36.     def process_tick(self):
  37.         for idx, vals in self.join.iteritems():
  38.             if vals[0] != float('inf') and vals[1] != float('inf'):
  39.                 log.debug("id: {0}, heat-index: {1} F"
  40.                           .format(idx, _heat_index(*vals)))
  41.         self.join.clear()

  42.     def process_tuple(self, tup):
  43.         measure = Measure(*tup.values)

  44.         # accept only measures within the update time window
  45.         if measure.timestamp < time.time() - self.conf.tick_tuple_freq:
  46.             return

  47.         # Since all components of this topology have a single output stream,
  48.         # the component id can be used to discriminate between the two streams
  49.         if tup.comp == "temperature-monitor":
  50.             if measure.measure > 80:
  51.                 self.join[measure.id_sensor][0] = measure.measure
  52.         elif tup.comp == "humidity-monitor":
  53.             if measure.measure > 40:
  54.                 self.join[measure.id_sensor][1] = measure.measure
  55.         else:
  56.             raise ValueError("Unexpected component stream: {0}"
  57.                              .format(tup.comp))

  58. if __name__ == '__main__':
  59.     logging.basicConfig(
  60.         level=logging.DEBUG,
  61.         filename='/tmp/apparent_temperature_heat_index.log',
  62.         filemode='a',
  63.     )

  64.     HeatIndexBolt().run()
复制代码

使用道具

藤椅
MouJack007 发表于 2017-3-24 15:46:25 |只看作者 |坛友微信交流群
谢谢楼主分享!

使用道具

板凳
MouJack007 发表于 2017-3-24 15:47:11 |只看作者 |坛友微信交流群

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-1 09:49