def test_assign_number_to_channel(self):
     c1 = Channel("c1")
     phone_numbers = list()
     channels = [c1]
     followings = [Following("u1", "c1")]
     self.assertIsNone(c1.phone_number)
     c1.assign_phone_number(phone_numbers, channels, followings)
     self.assertIsNotNone(c1.phone_number)
 def test_broadcast(self):
     c1 = Channel("c1")
     phone_numbers = list()
     channels = [c1]
     followings = [Following("u1", "c1")]
     self.assertIsNone(c1.phone_number)
     c1.broadcast(phone_numbers, channels, followings)
     self.assertIsNotNone(c1.phone_number)
 def test_least_impacted_channel(self):
     channels = [
         Channel("c1", "123", 1),
         Channel("c2", "123", 2),
         Channel("c3", "456", 3)
     ]
     channel = least_impacted_channel(channels)
     self.assertEqual(channel.channel_uid, "c1")
    def __init__(self, params: PhysicsParams, stats: ModelStats):

        super().__init__()

        self.channel = Channel(params.channel_params)

        self.params = params

        self.register_functions(stats)
 def test_get_least_used_number(self):
     phone_numbers = ["123", "456"]
     channels = [
         Channel("c1", "123"),
         Channel("c2", "123"),
         Channel("c3", "456")
     ]
     least_used_number = get_least_used_number(phone_numbers, channels)
     self.assertEqual(least_used_number, "456", "Got least used number")
 def test_is_collision_false(self):
     channels = [Channel("c1", "123"), Channel("c2"), Channel("c3", "123")]
     followers = [
         Following("u1", "c1"),
         Following("u3", "c3"),
         Following("u2", "c2"),
         Following("u4", "c2")
     ]
     collision = is_collision("123", "c2", channels, followers)
     self.assertEqual(collision, False)
def run():
    id = 'echo-radiodetaly'
    DEBUG('Start creating channel: ' + id)
    channel = Channel(id)
    channel.loadConfig()
    DEBUG('Channel ' + id + ' created', {
        'channel': channel,
    })
    channel.saveConfig()
 def test_minimum_phone_numbers_used(self):
     c1 = Channel("c1")
     c2 = Channel("c2")
     phone_numbers = list()
     channels = [c1, c2]
     followings = [Following("u1", "c1"), Following("u2", "c2")]
     phone_numbers = c1.broadcast(phone_numbers, channels, followings)
     self.assertEqual(len(phone_numbers), 1)
     phone_numbers = c2.broadcast(phone_numbers, channels, followings)
     self.assertEqual(len(phone_numbers), 1)
    def test_follow_channel_without_collision(self):
        c1 = Channel("c1")
        c2 = Channel("c2")
        u2 = User("u2")
        phone_numbers = list()
        channels = [c1, c2]
        followings = [Following("u1", "c1")]
        phone_numbers = c1.broadcast(phone_numbers, channels, followings)
        phone_numbers = c2.broadcast(phone_numbers, channels, followings)

        u2.follow_channel("c2", channels, phone_numbers, followings)
        self.assertEqual(c1.phone_number, c2.phone_number)
                          format(musicFile, e))
                    continue

                print("uploaded {0}, removing...".format(musicFile))
                os.remove(path + musicFile)

        print("Uploaded")
        continue

    return flag


if __name__ == '__main__':
    from src.Channel import Channel

    ch = Channel("./channelConfig/test.json")

    import configparser

    from telethon.sync import TelegramClient

    config = configparser.ConfigParser()
    config.read("Config.ini")

    # Присваиваем значения внутренним переменным
    api_id = config['Telegram']['api_id']
    api_hash = config['Telegram']['api_hash']
    session = config['Telegram']['session']
    client = TelegramClient(session=session, api_id=api_id, api_hash=api_hash)
    client.start()
class Physics(GridPhysics):

    def __init__(self, params: PhysicsParams, stats: ModelStats):

        super().__init__()

        self.channel = Channel(params.channel_params)

        self.params = params

        self.register_functions(stats)

    def register_functions(self, stats: ModelStats):
        stats.set_evaluation_value_callback(self.get_cral)

        stats.add_log_data_callback('cral', self.get_cral)
        stats.add_log_data_callback('cr', self.get_collection_ratio)
        stats.add_log_data_callback('successful_landing', self.has_landed)
        stats.add_log_data_callback('boundary_counter', self.get_boundary_counter)
        stats.add_log_data_callback('landing_attempts', self.get_landing_attempts)
        stats.add_log_data_callback('movement_ratio', self.get_movement_ratio)

    def reset(self, state: State):
        GridPhysics.reset(self, state)

        self.channel.reset(self.state.shape[0])

    def step(self, action: GridActions):
        old_position = self.state.position
        self.movement_step(action)
        if not self.state.terminal:
            self.comm_step(old_position)

        return self.state

    def comm_step(self, old_position):
        positions = list(
            reversed(np.linspace(self.state.position, old_position, num=self.params.comm_steps, endpoint=False)))

        indices = []
        device_list = self.state.device_list
        for position in positions:
            data_rate, idx = device_list.get_best_data_rate(position, self.channel)
            device_list.collect_data(data_rate, idx)
            indices.append(idx)

        self.state.collected = device_list.get_collected_map(self.state.shape)
        self.state.device_map = device_list.get_data_map(self.state.shape)

        idx = max(set(indices), key=indices.count)
        self.state.set_device_com(idx)

        return idx

    def get_example_action(self):
        return GridActions.HOVER

    def is_in_landing_zone(self):
        return self.state.is_in_landing_zone()

    def get_collection_ratio(self):
        return self.state.get_collection_ratio()

    def get_movement_budget_used(self):
        return sum(self.state.initial_movement_budgets) - sum(self.state.movement_budgets)

    def get_max_rate(self):
        return self.channel.get_max_rate()

    def get_average_data_rate(self):
        return self.state.get_collected_data() / self.get_movement_budget_used()

    def get_cral(self):
        return self.get_collection_ratio() * self.state.all_landed

    def get_boundary_counter(self):
        return self.boundary_counter

    def get_landing_attempts(self):
        return self.landing_attempts

    def get_movement_ratio(self):
        return float(self.get_movement_budget_used()) / float(sum(self.state.initial_movement_budgets))

    def has_landed(self):
        return self.state.all_landed
import os

from telethon.sync import TelegramClient

from src.Channel import Channel
from src.channelUpdate import channelUpdate


config = configparser.ConfigParser()
config.read("Config.ini")

api_id = config['Telegram']['api_id']
api_hash = config['Telegram']['api_hash']
session = config['Telegram']['session']


if __name__ == '__main__':

    TelegramClientInstance = TelegramClient(session=session, api_id=api_id, api_hash=api_hash)
    TelegramClientInstance.start()

    channelConfigFilesFolder = "./src/channelConfig/"

    channelList = [Channel(channelConfigFilesFolder + config) for config in os.listdir(channelConfigFilesFolder) if
                   config.endswith(".json")]

    while True:
        for channel in channelList:
            channelUpdate(channel, TelegramClientInstance, maxDurationInSeconds=720)
            print("sleep.... 360sec")
            sleep(360)
Exemple #13
0
# Testing slightly complex test cases

from src.Following import Following
from src.User import User
from src.Channel import Channel

channels = [Channel("c1"), Channel("c2"), Channel("c3")]
users = [User("u1"), User("u2"), User("u3"), User("u4")]
followings = [
    Following("u1", "c1"),
    Following("u3", "c3"),
    Following("u2", "c2"),
    Following("u4", "c2")
]
c1 = channels[0]
c2 = channels[1]
c3 = channels[2]

u1 = users[0]
u2 = users[1]
u3 = users[2]
u4 = users[3]

phone_numbers = list()

phone_numbers = c1.broadcast(phone_numbers, channels, followings)
phone_numbers = c3.broadcast(phone_numbers, channels, followings)
phone_numbers = c1.broadcast(phone_numbers, channels, followings)
phone_numbers = c2.broadcast(phone_numbers, channels, followings)
phone_numbers = c2.broadcast(phone_numbers, channels, followings)
phone_numbers = c2.broadcast(phone_numbers, channels, followings)
Exemple #14
0
 def get_data_rate(self, pos, channel: Channel):
     rate = channel.compute_rate(uav_pos=pos, device_pos=self.position)
     # self.data_rate_timeseries.append(rate)
     return rate