Exemple #1
0
    def simulate_progressive_ogp(self, replay=False, shuffle=False):
        ogp = OGPlanner(self.num_functions)
        cost, path = ogp.plan(self.num_functions, self.func_sel, self.func_cost)
        functions = list(filter(lambda x: x.id in path, self.functions))
        true = [0]
        false = [0]
        maybe = [0]
        cumu_cost = [0]
        items_batch = int(self.budget/cost)
        epoch = 1

        if shuffle:
            np.random.shuffle(self.items)

        for i in range(0, self.num_items, items_batch):
            items = self.items[i:i+items_batch]
            function_map = {self.items[j].id:functions for j in range(i, min(i+items_batch, self.num_items))}

            epoch_plan = plan.Plan(items, function_map)
            exec = executor.DefaultExectuor(epoch_plan, self.budget)

            if not replay:
                epoch_cost, epoch_true, epoch_false, epoch_maybe = exec.run()
            else:
                epoch_cost, epoch_true, epoch_false, epoch_maybe = exec.replay()

            true.append(true[-1]+len(epoch_true))
            false.append(false[-1]+len(epoch_false))
            maybe.append(len(epoch_maybe))
            cumu_cost.append(cumu_cost[-1]+epoch_cost)
            epoch += 1


        print(true[-1], false[-1], maybe[-1], epoch, items_batch)
        return (true, false, maybe, cumu_cost)
Exemple #2
0
def copyPlansWithMaxNumberActions(plan_file, path, maxActions): #funzione che sposta i piani con numero di azioni minore di maxActions
    try:
        piano = plan.Plan(plan_file)
        if len(piano.actions) <= maxActions:
            shutil.copy(plan_file, path)
    except IOError:
        a = 1
Exemple #3
0
    def _get_plan(self, part, part_size):
        if self._is_indirect:
            plan = _plan.Plan(part,
                              *self._unwound_args,
                              partition_size=part_size,
                              matrix_coloring=True,
                              staging=False,
                              thread_coloring=False)
        else:
            # TODO:
            # Create the fake plan according to the number of cores available
            class FakePlan(object):
                def __init__(self, part, partition_size):
                    self.nblocks = int(
                        math.ceil(part.size / float(partition_size)))
                    self.ncolors = 1
                    self.ncolblk = np.array([self.nblocks], dtype=np.int32)
                    self.blkmap = np.arange(self.nblocks, dtype=np.int32)
                    self.nelems = np.array([
                        min(partition_size, part.size - i * partition_size)
                        for i in range(self.nblocks)
                    ],
                                           dtype=np.int32)
                    self.offset = np.arange(part.offset,
                                            part.offset + part.size,
                                            partition_size,
                                            dtype=np.int32)

            plan = FakePlan(part, part_size)
        return plan
def get_plans(folder):
    plan_list = [
        plan.Plan(folder + "/" + file) for file in os.listdir(folder)
        if file.find("xml") >= 0 and (
            file.endswith(".soln") or file.endswith(".SOL"))
    ]
    return plan_list
Exemple #5
0
    def simulate_progressive_dynamic_ogp(self, replay=False):
        dynamic_ogp = OGDyanmicPlanner(self.items, self.num_functions, self.func_cost)
        tuple_plans = sorted(dynamic_ogp.plan(), key=lambda x: x.cost)

        true = [0]
        false = [0]
        maybe = [0]
        cumu_cost = [0]
        epoch = 1
        p_count = 0
        start = 0

        while p_count<len(self.items):

            cost = 0
            start = p_count
            function_map ={}
            while p_count<len(self.items) and cost<self.budget:
                cost += tuple_plans[p_count].cost
                path = tuple_plans[p_count].path
                functions = list(filter(lambda x: x.id in path, self.functions))
                function_map[self.items[p_count].id] = functions
                p_count += 1

            items = self.items[start:p_count]

            epoch_plan = plan.Plan(items, function_map)
            exec = executor.DefaultExectuor(epoch_plan, self.budget)

            if not replay:
                epoch_cost, epoch_true, epoch_false, epoch_maybe = exec.run()
            else:
                epoch_cost, epoch_true, epoch_false, epoch_maybe = exec.replay()

            true.append(true[-1]+len(epoch_true))
            false.append(false[-1]+len(epoch_false))
            maybe.append(len(epoch_maybe))
            cumu_cost.append(cumu_cost[-1]+epoch_cost)
            epoch += 1


        print (true[-1], false[-1], maybe[-1], epoch)
        return (true, false, maybe, cumu_cost)
Exemple #6
0
def start(profile=None, xml=True, dry_run=False, tree=None):
    # Load the profile
    if profile:
        # Read from a file
        with open(profile) as f:
            if xml:
                rtsp = rtsprofile.rts_profile.RtsProfile(xml_spec=f)
            else:
                rtsp = rtsprofile.rts_profile.RtsProfile(yaml_spec=f)
    else:
        # Read from standard input
        lines = sys.stdin.read()
        if xml:
            rtsp = rtsprofile.rts_profile.RtsProfile(xml_spec=lines)
        else:
            rtsp = rtsprofile.rts_profile.RtsProfile(yaml_spec=lines)

    # Build a list of actions to perform that will start the system
    checks, activates = activate_actions(rtsp)
    p = plan.Plan()
    p.make(rtsp, activates, rtsp.activation,
           rtctree.component.Component.ACTIVE)
    if dry_run:
        for a in checks:
            print a
        print p
    else:
        if not tree:
            # Load the RTC Tree, using the paths from the profile
            tree = rtctree.tree.RTCTree(paths=[
                rtctree.path.parse_path('/' + c.path_uri)[0]
                for c in rtsp.components
            ])
        try:
            for a in checks:
                a(tree)
            p.execute(tree)
        except rts_exceptions.RequiredActionFailedError:
            p.cancel()
            raise
def trans_girls_cron():
    """Config for trans girls cron"""
    cron = plan.Plan('trans_girls_rule_the_world')
    environment = {
        'TRANS_GIRLS_CONSUMER_KEY': os.environ['TRANS_GIRLS_CONSUMER_KEY'],
        'TRANS_GIRLS_CONSUMER_SECRET': os.environ['TRANS_GIRLS_CONSUMER_SECRET'],
        'TRANS_GIRLS_OAUTH_TOKEN': os.environ['TRANS_GIRLS_OAUTH_TOKEN'],
        'TRANS_GIRLS_OAUTH_SECRET': os.environ['TRANS_GIRLS_OAUTH_SECRET']
    }

    cron.command(
        'curl http://localhost:5000/post_selfie',
        every='10.minutes',
        environment=environment
    )

    #update cron if crontab exists, write new cron if crontab doesn't exist
    try:
        cron.run('update')

    except plan.PlanError:
        cron.run('write')
Exemple #8
0
def witches_cron():
    """Config for witches cron"""
    cron = plan.Plan('witches_rule_the_world')
    path = witches_rule_the_world.__path__[0]
    environment = {
        'WITCHES_CONSUMER_KEY': os.environ['WITCHES_CONSUMER_KEY'],
        'WITCHES_CONSUMER_SECRET': os.environ['WITCHES_CONSUMER_SECRET'],
        'WITCHES_OAUTH_TOKEN': os.environ['WITCHES_OAUTH_TOKEN'],
        'WITCHES_OAUTH_SECRET': os.environ['WITCHES_OAUTH_SECRET']
    }

    cron.script(
        'rule.py',
        every='10.minutes',
        path=path,
        environment=environment
    )

    #update cron if crontab exists, write new cron if crontab doesn't exist
    try:
        cron.run('update')

    except plan.PlanError:
        cron.run('write')
Exemple #9
0
def _makeInfoPageInfo(the_user, the_gig, the_band_key):
    gig_key = the_gig.key

    the_assocs = assoc.get_assocs_of_band_key(the_band_key,
                                              confirmed_only=True,
                                              keys_only=False)

    # get all the plans for this gig - might actually not be any yet.
    all_plans = plan.get_plans_for_gig_key(gig_key, keys_only=False)

    # now, for each associated member, find or make a plan
    the_plans = []
    the_new_plans = []  # in case we need to make new ones

    the_plan_counts = {}
    for i in range(len(plan.plan_text)):
        the_plan_counts[i] = 0

    need_empty_section = False
    for the_assoc in the_assocs:
        a_member_key = the_assoc.member
        new_plan = False

        for p in all_plans:
            if p.member == a_member_key:
                the_plan = p
                break
        else:
            # no plan? make a new one
            planval = 0
            if (the_gig.default_to_attending):
                planval = 1

            the_plan = plan.Plan(parent=gig_key,
                                 member=a_member_key,
                                 value=planval,
                                 comment="",
                                 section=None)
            the_new_plans.append(the_plan)
            new_plan = True

        if (not the_assoc.is_occasional) or \
           (the_assoc.is_occasional and the_plan.value != 0) or \
           (a_member_key == the_user.key) or \
           the_user.is_superuser:
            if the_plan.section == None and the_assoc.default_section == None:
                need_empty_section = True
            info_block = {}
            info_block['the_gig_key'] = the_gig.key
            info_block['the_plan'] = the_plan
            info_block['the_member_key'] = a_member_key
            info_block['the_band_key'] = the_band_key
            info_block['the_assoc'] = the_assoc
            if the_plan.section is not None:
                info_block['the_section'] = the_plan.section
            else:
                info_block['the_section'] = the_assoc.default_section
            the_plans.append(info_block)
            the_plan_counts[the_plan.value] += 1

    if the_new_plans:
        ndb.put_multi(the_new_plans)

    the_section_keys = band.get_section_keys_of_band_key(the_band_key)
    the_sections = ndb.get_multi(the_section_keys)
    if need_empty_section:
        the_sections.append(None)

    if len(the_section_keys) == 0:
        band_has_sections = False
    else:
        band_has_sections = True

    return the_plans, the_plan_counts, the_sections, band_has_sections
Exemple #10
0
def get_plans(folder):
    plan_list = [
        plan.Plan(folder + "/" + file) for file in os.listdir(folder)
        if file.endswith(".SOL")
    ]
    return plan_list
Exemple #11
0
    def _make_page(self, the_user):

        # find the gig we're interested in
        gig_key_str = self.request.get("gk", None)
        if gig_key_str is None:
            self.response.write('no gig key passed in!')
            return  # todo figure out what to do if there's no ID passed in

        gig_key = ndb.Key(urlsafe=gig_key_str)
        the_gig = gig_key.get()

        if the_gig is None:
            template_args = {}
            self.render_template('no_gig_found.html', template_args)
            return  # todo figure out what to do if we didn't find it

        the_comment_text = None
        if the_gig.comment_id:
            the_comment_text = gigcomment.get_comment(the_gig.comment_id)

        if not the_gig.is_archived:
            the_band_key = the_gig.key.parent()

            the_assocs = assoc.get_assocs_of_band_key(the_band_key,
                                                      confirmed_only=True,
                                                      keys_only=False)

            # get all the plans for this gig - might actually not be any yet.
            all_plans = plan.get_plans_for_gig_key(gig_key, keys_only=False)

            # now, for each associated member, find or make a plan
            the_plans = []
            the_new_plans = []  # in case we need to make new ones

            the_plan_counts = {}
            for i in range(len(plan.plan_text)):
                the_plan_counts[i] = 0

            need_empty_section = False
            for the_assoc in the_assocs:
                a_member_key = the_assoc.member
                new_plan = False

                for p in all_plans:
                    if p.member == a_member_key:
                        the_plan = p
                        break
                else:
                    the_plan = plan.Plan(parent=gig_key,
                                         member=a_member_key,
                                         value=0,
                                         comment="",
                                         section=None)
                    the_new_plans.append(the_plan)
                    new_plan = True

                if (not the_assoc.is_occasional) or \
                   (the_assoc.is_occasional and the_plan.value != 0) or \
                   (a_member_key == the_user.key) or \
                   the_user.is_superuser:
                    if the_plan.section == None and the_assoc.default_section == None:
                        need_empty_section = True
                    info_block = {}
                    info_block['the_gig_key'] = the_gig.key
                    info_block['the_plan'] = the_plan
                    info_block['the_member_key'] = a_member_key
                    info_block['the_band_key'] = the_band_key
                    info_block['the_assoc'] = the_assoc
                    if the_plan.section is not None:
                        info_block['the_section'] = the_plan.section
                    else:
                        info_block['the_section'] = the_assoc.default_section
                    the_plans.append(info_block)
                    the_plan_counts[the_plan.value] += 1

            if the_new_plans:
                ndb.put_multi(the_new_plans)

            the_section_keys = band.get_section_keys_of_band_key(the_band_key)
            the_sections = ndb.get_multi(the_section_keys)
            if need_empty_section:
                the_sections.append(None)

            if len(the_section_keys) == 0:
                band_has_sections = False
            else:
                band_has_sections = True

            # is the current user a band admin?
            the_user_is_band_admin = assoc.get_admin_status_for_member_for_band_key(
                the_user, the_band_key)
            the_band = the_band_key.get()
            user_can_edit = can_edit_gig(the_user, the_gig, the_band)
            user_can_create = can_edit_gig(the_user, None, the_band)

            datestr = member.format_date_for_member(the_user,
                                                    the_gig.date,
                                                    format="long")
            if the_gig.enddate:
                enddatestr = u' - {0}'.format(
                    member.format_date_for_member(the_user,
                                                  the_gig.enddate,
                                                  format="long"))
            else:
                enddatestr = ''

            template_args = {
                'gig': the_gig,
                'date_str': datestr,
                'enddate_str': enddatestr,
                'the_plans': the_plans,
                'the_sections': the_sections,
                'comment_text': the_comment_text,
                'band_has_sections': band_has_sections,
                'the_user_is_band_admin': the_user_is_band_admin,
                'user_can_edit': user_can_edit,
                'user_can_create': user_can_create,
                'the_plan_counts': the_plan_counts
            }
            self.render_template('gig_info.html', template_args)

        else:
            # this is an archived gig
            the_archived_plans = gigarchive.get_archived_plans(
                the_gig.archive_id)
            template_args = {
                'gig': the_gig,
                'archived_plans': the_archived_plans,
                'comment_text': the_comment_text
            }
            self.render_template('gig_archived_info.html', template_args)
Exemple #12
0
# out_filename_phase3 = sys.argv[5]
# out_filename_phase4 = sys.argv[6]
# out_filename_phase5 = sys.argv[7]

if debug_level > 1:
    print('args :', len(sys.argv))

indu_comp = 'comp'
ic_name = 'all'

if len(sys.argv) == 9:
    indu_comp = sys.argv[5]
    ic_name = sys.argv[6]
    ic_name = ic_name.capitalize()

plan = plan.Plan()

plan.set_debug_level(debug_level)

if truncate_table:
    plan.plan_table_reload(truncate_table)

plan.amfi_load_db()
plan.plan_load_data(in_filename_phase[0])

plan.plan_dump_ticker(out_filename_phase[0])
plan.plan_dump_sorted_units(out_filename_phase[1])
plan.plan_dump_all(out_filename_phase[2])
plan.plan_dump_plus(out_filename_phase[3])
plan.plan_dump_zero(out_filename_phase[4])