Esempio n. 1
0
 def divide_vars(self, var_decl):
     self.var_list = {}
     for _stmt in var_decl.split('\n'):
         stmt = _stmt.strip()
         if len(stmt) > 0:
             tmp = stmt.split(' ')
             var_type = tmp[0]
             name = tmp[-1][:-1]  #skip ';'
             self.var_list[name] = Var(var_type)
Esempio n. 2
0
 def __init__(self, canvas, row, col, my=True, tag="empty"):
     self.c = canvas
     self.row = row
     self.col = col
     self.my = my
     self.var = Var()
     self.tag = tag
     self.index = None
     self.draw()
Esempio n. 3
0
 def __init__(self, canvas, my=True):
     self.c = canvas
     self.my = my
     self.var = Var()
     if my:
         x = self.var.lr_span
     else:
         x = self.var.lr_span + self.var.center_span + self.var.see_field_width
     self.index = self.c.create_rectangle(x, self.var.top_span, \
         x + self.var.see_field_width, \
         self.var.top_span + self.var.see_field_height, \
         fill = self.var.see_color, outline = self.var.see_color)
Esempio n. 4
0
    def create_used_var(self, var_name):
        """Creates Var instance.

        Sets the instance to this object's used_variable.

        Args:
            var_name: the variable name used

        Returns:
            A Var instance
        """
        self.used_variable = Var(name=var_name)
        return self.used_variable
Esempio n. 5
0
 def divide_params(self, func_decl):
     self.param_name = []  #这个字段用来按顺序专门记录各个参数名
     self.param_list = {}
     para_decl = re.findall(Context.PARENTHESE_PATTERN,
                            func_decl)[0].strip('()')
     for _stmt in para_decl.split(','):
         stmt = _stmt.strip()
         if len(stmt) > 0:
             tmp = stmt.split(' ')
             var_type = tmp[0]
             name = tmp[-1]
             self.param_list[name] = Var(var_type)
             self.param_name.append(name)
Esempio n. 6
0
 def __init__(self, canvas, number, direction='h', my=True):
     #number: 0 - 4, 1..2  - 3, 3..5 - 2, 6..9 - 1 палубный
     self.c = canvas
     self.my = my
     self.var = Var()
     self.number = number
     self.direction = direction
     self.see_blocks = []
     self.mini_blocks = []
     self.live = "live"  #demage, kill
     self.block_status = []
     self.status = "none"
     self.x = 0
     self.y = 0
     self.drawed = False
     self.selected = False
     self.draw_mini()
Esempio n. 7
0
    def newvar(self, name, setnames=None, header=None, par=False):
        """Create a new variable and add it to the model.

        Args:
            name (str): Name of variable or parameter
            setnames (list): List of set names
            header (str): GEMPACK header
            par (bool): True if a parameter

        Returns:
             Var: new object.
        """
        _add_name(name, self.dat_names)
        item = Var(name, setnames, header, par=par)
        self.dats[name] = item
        if par:
            self.par_names.append(name)
        else:
            self.var_names.append(name)
        return item
Esempio n. 8
0
#! /usr/bin/env python3
# _*_ coding: utf-8 _*_

import pygame  # pygame
from var import Var  # for const
from ship import Ship  # ship
from scores import Scores
from sounds import Sounds
import game_functions as gf  # Game functions
from pygame.sprite import Group

pygame.init()
ai_var = Var()
screen = pygame.display.set_mode([ai_var.screen_width, ai_var.screen_height])
pygame.display.set_caption("Alien War")
ship = Ship(screen)
sc = Scores(screen, ai_var)
sd = Sounds()
timer = pygame.time.Clock()
bullets = Group()
aliens = Group()


def main():
    while sc.game_active:  # Game Started
        gf.check_events(ship, ai_var, screen, bullets, sc, sd)  # Check events
        ship.update(ai_var)  # Update the status of the ship
        bullets.update()
        aliens.update(sc)
        gf.update_aliens(aliens, screen, ai_var, bullets, sc, ship, sd)
        gf.remove(bullets, aliens, screen)
Esempio n. 9
0
bins_invM_3 = generateLogBins(8,130,200)
bins_invM_4 = generateLogBins(6,90,200)
bins_Zpeak = [50,70,74,77,80,82,83,84,85,86,87,88,89,90,91,92,93,94,95,97,99,102,105,110,130]
bins_Zpeak2 = [50,80,100,130]
bins_met = generateLogBins(15,1,1000)
bins_met_2 = generateLogBins(50,25,2000)
"""

bins_pt_2 = generateLogBins(20, 30, 1000)

## Event variables
## ---------------------------------------
averageIntPerXing = Var(
    name='averageIntPerXing',
    path='event',
    xmin=0,
    xmax=45,
    log=False,
)

actualIntPerXing = Var(
    name='actualIntPerXing',
    path='event',
    xmin=0,
    xmax=45,
    log=False,
)

NPV = Var(
    name='NPV',
    path='event',
Esempio n. 10
0
# encoding: utf-8
'''
vars.py
description:
variables for plotting
'''

## modules
from var import Var

## Event variables
## ---------------------------------------
nmuons = Var(
    name='nmuons',
    path='event',
    xmin=0,
    xmax=5,
    log=False,
)

n_vx = Var(
    name='n_vx',
    path='event',
    xmin=0,
    xmax=14,
    #         rebin   = 0,
    log=False,
)

## Muon variables
## ---------------------------------------
Esempio n. 11
0
# encoding: utf-8
'''
vars.py
description:
variables for all the channels
'''

## modules
from var import Var
from funcs import generateLogBins

## Cutflows
## ---------------------------------------
cutflow_weighted = Var(name='cutflow_weighted_mumu', log=False)
cutflow = Var(name='cutflow_mumu', log=False)
cutflow_weighted_mu_pairs = Var(name='cutflow_weighted_mumu_mu_pairs',
                                log=False)
cutflow_mu_pairs = Var(name='cutflow_mumu_mu_pairs', log=False)
cutflow_presel = Var(name='cutflow_presel', log=False)
cutflow_weighted_presel = Var(name='cutflow_weighted_presel', log=False)
cutflow_ZCR = Var(name='cutflow_ZCR', log=False)
cutflow_weighted_ZCR = Var(name='cutflow_weighted_ZCR', log=False)

bins_pt = generateLogBins(10, 30, 400)
bins_pt_4lep = generateLogBins(5, 30, 200)
bins_pt_2 = generateLogBins(8, 30, 400)
#bins_mVis = generateLogBins(25,20,900) # ttbar CR
#bins_mVis = generateLogBins(15,60,200) # bins for CRs
#bins_mVis = generateLogBins(20,30,3000) # bins for plotting
#bins_mVis = generateLogBins(5,200,900) #bins for SRs
bins_mVis = generateLogBins(23, 200, 1350)  #bins for SRs
Esempio n. 12
0
def parse(f):
    def add_var(d, v):
        # Do nothing if var is none. Gracefully handles first variable,
        # and after that point var is never None
        if v is None:
            return

        if v.ctype == 'string' and v.size is None:
            raise ValueError('String %s has no length' % v.name)
        if v.address is None:
            raise ValueError('Var %s has no address' % v.name)
        if v.vartype is None:
            raise ValueError('Var %s has no type' % v.name)

        d.vars.append(v)

    device = None
    var = None
    group = None
    custom = False
    cur_address = 0
    cur_interval = 0
    cur_filter = None
    cur_iwrite = None

    for line in f:
        line = line.strip()
        if line == '':
            pass
        elif line[0] == '$':
            pass
        elif line[0] == '@':
            line_result = line.split(',', 3)
            for i in range(len(line_result)):
                line_result[i] = line_result[i].strip('@' + string.whitespace)
            if device is None:
                device = Device(line_result[0])
                group = line_result[0]
            else:
                err = 'Duplicate device line in file (Had %s, now have %s)' \
                    % (device.name, line_result[0])
                raise ValueError(err)
            device.id = int(line_result[1])
            if line_result[2] == '/dev/ttyUSB0':
                device.path = 'autodetect'
            else:
                device.path = line_result[2]
            device.baud_rate = int(line_result[3])
        elif line[0] == ';':
            line = line.strip(';' + string.whitespace)
            if line.startswith('group:'):
                line_result = line[6:].split(',', 2)
                for i in range(len(line_result)):
                    line_result[i] = line_result[i].strip()
                group = line_result[0]
                if device is None:
                    raise ValueError('Group %s has no device' % group)
                else:
                    if bools[line_result[1]] == True:
                        if group not in device.write_only_groups:
                            device.write_only_groups.append(group)
                    else:
                        if group in device.write_only_groups:
                            raise ValueError('Group %s is already write only' %
                                             group)
            elif line.startswith('filter:'):
                line_result = line[7:].strip()
                cur_filter = line_result
            elif line.startswith('no_initial_write'):
                cur_iwrite = True
        elif line[0] == '#':
            line_result = line.split(',', 3)
            for i in range(len(line_result)):
                line_result[i] = line_result[i].strip('#' + string.whitespace)
            cur_address = int(line_result[0])
            cur_interval = int(line_result[1])
            custom = bools[line_result[2]]
        elif custom == True:
            line_result = line.split(',', 5)
            for i in range(len(line_result)):
                line_result[i] = line_result[i].strip()
            (g, v) = line_result[2].split('/', 1)
            if device is None:
                raise ValueError('Var %s has no device' % g)
            var = Var(g, v)
            var.vartype = line_result[1]
            if line_result[1] == 'string':
                var.ctype = 'string'
            else:
                var.ctype = ctypes[line_result[1]]
            var.size = int(line_result[0])
            var.readonly = bools[line_result[4]]
            var.address = cur_address
            cur_address += int(line_result[0])
            var.interval = cur_interval
            if cur_filter is not None:
                var.filter = cur_filter
                cur_filter = None
            if cur_iwrite is not None:
                var.iwrite = False
                cur_iwrite = None
            add_var(device, var)

    if device.path is None:
        raise ValueError('Device %s has no path' % device.name)
    if device.id is None and device.path == 'autodetect':
        raise ValueError('Device %s is autodetect but no id' % device.name)

    return device
Esempio n. 13
0
# encoding: utf-8
'''
vars.py
description:
variables for plotting
'''

## modules
from var import Var

## Event variables
## ---------------------------------------
nmuons = Var(
    name='nmuons',
    path='event',
    xmin=0,
    xmax=5,
    log=False,
)

## Muon variables
## ---------------------------------------
mu_pt = Var(
    name='mu_pt',
    path='muons',
    xmin=0,
    xmax=150,
    rebin=10,
    log=False,
)