コード例 #1
0
# https://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points
from math import radians, cos, sin, asin, sqrt
import requests

from dispatch.plugins.bases.kandbox_planner import KandboxTravelTimePlugin

from dispatch.plugins.kandbox_planner.util.cache_dict import CacheDict

travel_time_dict = CacheDict(cache_len=5000)

import logging

log = logging.getLogger(__file__)


class TaxicabTravelTime(KandboxTravelTimePlugin):
    """
    Has the following members
    """

    travel_speed = 1  # 5 blocks / minute

    def __init__(self, travel_speed=None):
        if travel_speed is not None:
            self.travel_speed = travel_speed

    def get_travel_minutes_2locations(self, loc_1,
                                      loc_2):  # get_travel_time_2locations

        distance = abs(float(loc_1[0]) - float(loc_2[0])) + abs(
            float(loc_1[1]) - float(loc_2[1]))
コード例 #2
0
# )

# from dispatch.plugins.kandbox_planner.agent.kprl_agent_rllib_ppo import KandboxAgentRLLibPPO
import dispatch.plugins.kandbox_planner.util.kandbox_date_util as date_util

import dispatch.config as config
import logging

log = logging.getLogger(__name__)
"""
import ray

if not ray.is_initialized():
    ray.init(ignore_reinit_error=False, log_to_driver=False, local_mode=True, num_cpus=1)
"""
planners_dict = CacheDict(
    cache_len=5)  # planners[(org_code,team_id,start_day)]= the_planner
# TODO org_code authentication.

from dispatch.plugins.kandbox_planner.env.env_enums import EnvRunModeType

import redis

if REDIS_PASSWORD == "":
    redis_conn = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, password=None)
else:
    redis_conn = redis.Redis(host=REDIS_HOST,
                             port=REDIS_PORT,
                             password=REDIS_PASSWORD)

import threading
コード例 #3
0
            log.info('Sending message to stream "%s", topic "%s"... ' %
                     (message_data["to"], message_data["topic"]))
        else:
            log.info("Sending message to {}... ".format(message_data["to"]))
        response = self.client.send_message(message_data)
        if response["result"] == "success":
            log.info("Message sent.")
            return True
        else:
            log.error(response["msg"])
            return False

    def delete_message(self, message_id):

        result = self.client.delete_message(message_id)
        self.log_result(result)
        return result


all_zulip_client_dict = CacheDict(cache_len=9999)
all_zulip_client_dict = get_zulip_client()
all_zulip_client_dict_by_org_code = {}
for v in all_zulip_client_dict.values():
    all_zulip_client_dict_by_org_code[v["org_obj"].code] = v["client"]

if __name__ == "__main__":
    core = ZulipCore()
    me = core.users_core.get_user_by_email('@1.com')
    user_id = me['user']['user_id']
    print(user_id)
コード例 #4
0
ファイル: database.py プロジェクト: alibaba/easydispatch
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey

log = logging.getLogger(__file__)


QueryStr = constr(regex=r"^[ -~]+$", min_length=1)

engine = create_engine(
    str(SQLALCHEMY_DATABASE_URI),
    pool_size=40,
    max_overflow=20,
    # echo=True,
)
log.debug(f"database engine created:{engine}")
SessionLocal = sessionmaker(bind=engine)
engine_dict = CacheDict(cache_len=5)
session_dict = CacheDict(cache_len=5)
# sqlalchemy core
try:
    conn_core = engine.connect()
except:
    pass
metadata = MetaData(engine)
try:
    worker_table = Table('worker', metadata, autoload=True)
    job_table = Table('job', metadata, autoload=True)
    location_table = Table('location', metadata, autoload=True)
    event_table = Table('event', metadata, autoload=True)
except:
    print("Failed to load tables ... Ignore this if you are creating database ...")