Exemple #1
0
def force_sync():
    stop_containers()
    parallel([
        'peg sshcmd-cluster {} "rm -rf ~/heart_watch"'.format(cluster)
        for cluster in CLUSTERS
    ])
    sync()
Exemple #2
0
        # only include images which have entities present in pairs
        images = [
            img for img in images
            if any(id in eids for id in img.entities.keys())
        ]
        logger.info('pairs: {}'.format(len(pairs)))
        logger.info('images: {}'.format(len(images)))

        if len(pairs) >= config.MIN_PAIRS:
            fname = datetime.utcnow().strftime('%Y%m%d%H%M')
            meta = render(images,
                          pairs,
                          out='public/vault/{}.jpg'.format(fname))
            if meta is not None:
                with open('public/vault/{}.json'.format(fname), 'w') as f:
                    json.dump(meta, f)

                tmpl = open('assets/templates/index.html', 'r').read()
                figs = [
                    '<figure><img src="{}"></figure>'.format(
                        im.replace('public/', ''))
                    for im in sorted(glob('public/vault/*.jpg'), reverse=True)
                ]
                html = tmpl.format(figures='\n'.join(figs))
                with open('public/index.html', 'w') as f:
                    f.write(html)
                util.sync()
        else:
            print('no dice')
        sleep(config.INTERVAL)
Exemple #3
0
# -*- coding: utf-8 -*-
import sys
sys.path.insert(0, '../')
import util
import config
import common

if __name__ == '__main__':

	endpoint_name = sys.argv[-3]
	endpoint = sys.argv[-2]
	redis_ch = sys.argv[-1]

	if config.hostname in common.master_servers or util.check_local_dev():
		util.sync(endpoint=endpoint, redis_ch=redis_ch, endpoint_name=endpoint_name)
	else:
		sys.exit('Unknown host {}'.format(config.hostname))
    return recent


async def check_new_sticker_usage(c: TelegramClient,
                                  old_recent: List[RecentSticker],
                                  log_chat: Entity) -> List[RecentSticker]:
    new_recent = await list_recent_stickers(c)
    for new in new_recent:
        if new not in old_recent:
            print(
                f"Posting new sticker: {new.sticker.emoji} {new.sticker.sticker_id}"
            )
            await c.send_file(log_chat, new.sticker.document)
        else:
            break
    new_recent = await list_recent_stickers(c)
    return new_recent


if __name__ == '__main__':
    client = telethon.TelegramClient('sticker_counter', api_id, api_hash)
    client.start()
    recent_stickers = sync(client, list_recent_stickers(client))
    chat = sync(client, client.get_entity(chat_id))
    print("Startup complete")
    while True:
        recent_stickers = sync(
            client, check_new_sticker_usage(client, recent_stickers, chat))
        print("Waiting for more...")
        sleep(60)
Exemple #5
0
        neuron: int, neuron index in neural_data.
        bin_size_cm: float, bin size in centimeters.
        plot: bool, flag for plotting.

        :return
        ---
        pf: (x,y) array, 2d histogram of position weighted by activity.
        """
        pf, xedges, yedges = \
            self.bin(self.x, self.y, bin_size_cm=bin_size_cm, plot=False,
                     weights=self.neural_data[neuron])

        # Normalize by occupancy.
        pf = pf / self.occupancy_map
        if plot:
            plt.imshow(pf, origin='lower')

        return pf


if __name__ == '__main__':
    dpath = r'D:\Projects\GTime\Data\G123\2\H14_M46_S20'
    bpath = os.path.join(r'D:\Projects\GTime\Data\G123\2\H14_M46_S20\Behavior',
                         'Merged_tracked.csv')
    minian = open_minian(dpath)

    position = read_eztrack(bpath)
    position = sync(position, np.asarray(minian.S))

    P = PlaceFields(position['x'], position['y'], np.asarray(minian.S))
    P.plot_dots(1)
Exemple #6
0
    sticker_ids = Counter(sticker_id_list)
    sticker_set_ids = Counter(set_list)
    sticker_set_str = "Counter(" + ', '.join(
        f"\"{sset}\": {n}" for sset, n in sticker_set_ids.most_common()) + ")"
    return [
        f"Emoji counter: {emoji}", f"Sticker ID counter: {sticker_ids}",
        f"Set counter: {sticker_set_str}"
    ]


async def send_top_stickers(c: TelegramClient, chat: Entity,
                            sticker_list: List[StickerMessage],
                            count: int) -> None:
    counter = Counter([msg.sticker for msg in sticker_list])
    position = 1
    for sticker, n in counter.most_common(count):
        await c.send_message(chat, f"Sticker #{position}, used on {n} days:")
        await c.send_file(chat, sticker.document)
        position += 1


if __name__ == '__main__':
    client = telethon.TelegramClient('sticker_counter', api_id, api_hash)
    client.start()
    sticker_chat = sync(client, client.get_entity(chat_id))
    stickers = sync(client, scrape_chat(client, sticker_chat))
    stats_msgs = generate_stats_messages(stickers)
    for stats_msg in stats_msgs:
        sync(client, client.send_message(sticker_chat, stats_msg))
    sync(client, send_top_stickers(client, "me", stickers, 5))