Esempio n. 1
0
def RingPosition(ring,coord,box):
    c = np.zeros(3)
    center = wr.wrap(coord[ring[0]],box)
    for node in ring:
        d = coord[node] - center
        d = wr.wrap(d,box)
        c += d
    return center + c / len(ring)
Esempio n. 2
0
 def run():
     pid = os.fork()
     if pid == 0:
         wrap.wrap(fnc)
         sys.exit(0)
     else:
         pid, s = os.waitpid(pid, 0)
         if os.WIFEXITED(s):
             s = os.WEXITSTATUS(s)
             if s != 0:
                 sys.exit(s)
         else:
             sys.exit(10)
Esempio n. 3
0
 def run():
     pid = os.fork()
     if pid == 0:
         wrap.wrap(fnc)
         sys.exit(0)
     else:
         pid, s = os.waitpid(pid, 0)
         if os.WIFEXITED(s):
             s = os.WEXITSTATUS(s)
             if s != 0:
                 sys.exit(s)
         else:
             sys.exit(10)
Esempio n. 4
0
 def display(self):
     if self.changed:
         self.cache = wrap.wrap(self.text, self.font, self.fontWidth)
         self.currentLines = len(self.cache)
         self.changed = False
     self.surface.fill(self.background)
     y = self.rectangle.height
     if self.offsetY == 0:
         slice = None
     else:
         slice = -self.offsetY
     for l in reversed(self.cache[:slice]):
         y -= self.lineSize
         rendered = False
         for length, substr, fg, bg in self.tags:
             if substr == l[0:length]:
                 renderedLine = self.font.render(l, 1, fg, bg)
                 rendered = True
                 break
         if not rendered:
             renderedLine = self.font.render(l, 1, self.foreground,
                                             self.background)
         oneline = pygame.Rect(self.xOffset, y, self.fontWidth,
                               self.fontHeight)
         self.surface.blit(renderedLine, oneline)
         if y < self.lineSize:
             break
Esempio n. 5
0
    def test_word_wrap(self):
        test_txt = self.read_file('before.txt')
        correct_text = self.read_file('after.txt')
        result_txt = wrap(test_txt)

        self.assertIsNotNone(result_txt)

        result_lines = string.split(result_txt, "\n")
        correct_lines = string.split(correct_text, "\n")

        for i, line in enumerate(correct_lines):

            self.assertEqual(line, result_lines[i])

        for i, line in enumerate(result_lines):

            self.assertEqual(line, correct_lines[i])

        self.assertEqual(correct_text, result_txt)
Esempio n. 6
0
    def update(self, cmd, state):

        # lateral autopilot
        chi_c = wrap(cmd.course_command, state.chi)
        print('State Chi: ', state.chi, 'Chi_C: ', chi_c)
        phi_c = self.saturate(
            cmd.phi_feedforward +
            self.course_from_roll.update(chi_c, state.chi), -np.radians(30),
            np.radians(30))
        print('Phi C: ', phi_c)
        delta_a = self.roll_from_aileron.update(phi_c, state.phi,
                                                state.rigid_body[10])
        delta_r = self.yaw_damper.update(state.rigid_body[12])

        # longitudinal autopilot
        # saturate the altitude command
        h_c = self.saturate(cmd.altitude_command,
                            state.rigid_body[2] - AP.altitude_zone,
                            state.rigid_body[2] + AP.altitude_zone)
        print('h_c: ', h_c, 'h: ', -state.rigid_body[2], 'altitude command: ',
              cmd.altitude_command)
        theta_c = self.altitude_from_pitch.update(h_c, -state.rigid_body[2])
        print(theta_c)
        delta_e = self.pitch_from_elevator.update(theta_c, state.theta,
                                                  state.rigid_body[11])
        # print('delta e', delta_e)
        delta_t = self.airspeed_from_throttle.update(cmd.airspeed_command,
                                                     state.airspeed)

        # construct output and commanded states
        delta = np.array([[delta_e], [delta_a], [delta_r], [delta_t]])
        self.commanded_state.h = cmd.altitude_command
        self.commanded_state.Va = cmd.airspeed_command
        self.commanded_state.phi = phi_c
        self.commanded_state.theta = theta_c
        self.commanded_state.chi = cmd.course_command
        return delta.flatten(), self.commanded_state
Esempio n. 7
0
def ChiralityInDihedralAngle_general2(a,b, nei,coord, box):
    #if len(nei[a]) != 4 or len(nei[b]) != 4:
    #    # not target
    #    return 0.0
    #1. make vertices list
    pivots = (a,b)
    center = coord[a]
    vertices = set(nei[a]) | set(nei[b])
    #2. calculate the direction vectors
    localcoord = dict()
    for vertex in vertices:
        localcoord[vertex] = wr.wrap(coord[vertex] - center, box)
    vertices -= set(pivots)
    pivot = localcoord[b] - localcoord[a]
    pivot /= np.linalg.norm(pivot)
    #direction vectors, perpendicular to the pivot vector
    vectors = dict()
    for vertex in vertices:
        v = localcoord[vertex] - np.dot(pivot,localcoord[vertex])*pivot
        vectors[vertex] = v / np.linalg.norm(v)
    va = list(set(nei[a]) - set(pivots))
    vb = list(set(nei[b]) - set(pivots))
    #check
    #for i in va + vb:
    #    sine = np.dot(np.cross(vectors[i],vectors[va[0]]), pivot)
    #    cosine = np.dot(vectors[i],vectors[va[0]])
    #    angle = math.atan2(sine,cosine) * 180 / math.pi
    #    #print angle
    op = []
    for i in va:
        for j in vb:
            sine = np.dot(np.cross(vectors[i],vectors[j]), pivot)
            cosine = np.dot(vectors[i],vectors[j])
            angle = math.atan2(sine,cosine)# * 180 / math.pi
            op.append(math.sin(angle*3))
    return op
Esempio n. 8
0
        #        messagebus.notify(topic="request.notify", user=user.login, **r.dump_json())
        handle_notification(r, user)
    else:
        msg = "%s: don't know how to handle requests of this kind '%s'" \
                        % (user.get_login(), r.kind)
        log.alert(msg)
        m = user.message_to()
        m.set_headers(subject="unknown request")
        m.write_line(msg)
        m.send()
    status.pop()
    return True


def handle_request_main(req, filename=None):
    acl.try_reload()
    blacklist.try_reload()
    init_conf("src")
    status.push("handling email request")
    ret = handle_request(req, filename=filename)
    status.pop()
    return ret


def main():
    sys.exit(not handle_request_main(sys.stdin.read()))


if __name__ == '__main__':
    wrap.wrap(main)
Esempio n. 9
0
                order += 1
    adjacencygraph = ra.AdjacencyGraph(nring_, ringsets)
    for edge in adjacencygraph:
        if 0 < len(kinds) and not edge.intersection(members) == edge:
            continue
        #edge is a set of vertices, not list
        #p is the tuple of ringsets 
        p = tuple([x for x in edge])
        ids = tuple([idlist[x] for x in p])
        #determine the layer
        if 0 < len(kinds):
            layer = len(kinds) + orderdict[ids]
            s += yp.Layer(2+layer)
            s += yp.Color(3+layer)
        v = [ringsetpositions[x] for x in p]
        d = wr.wrap(v[1]-v[0],box)
        s += yp.Line(v[0], v[0]+d)


#Fragment shapes
for i in range(len(ringsets)):
    #draw polyhedron
    if 0 < len(kinds) and not i in members:
        continue
    if 0 < len(kinds):
        order = kinds.index(idlist[i])
        s += yp.Layer(order+2)
        s += yp.Color(order+3)
    else:
        size = len(ringsets[i])
        s += yp.Layer(size - 1)
Esempio n. 10
0
 def test_big_string_without_spaces(self):
     self.assertEqual('ab\ncd\nef\ngh', wrap('abcdefgh', 2))
Esempio n. 11
0
#!/usr/bin/env python

import taskpaper
import mailapp
import wrap

content = taskpaper.get_open_task_paper_doc_as_text()

content = wrap.wrap(content)

mailapp.make_message(
    content,
    subject="snapshot",
    to_addr=["*****@*****.**", "*****@*****.**"],
    from_addr="Jachin Rupe <*****@*****.**>",
)
Esempio n. 12
0
 def connectionMade(self):
     if types.ClassType == type(self.controller):
         self._controller = wrap(self.controller(self))
     else:
         self._controller = wrap(self.controller())
     self._execute()
Esempio n. 13
0
 def test_string_with_space_at_column(self):
     self.assertEqual('word\nword', wrap('word word', 5))
Esempio n. 14
0
    def create_pdf(self, user, repo, issue):
        self.debug('Create', 'Creating PDF.')

        os.chdir('pdf')
    
        if not (os.path.isdir(user)):
            os.mkdir(user)
        
        os.chdir(user)

        if not (os.path.isdir(repo)):
            os.mkdir(repo)

        os.chdir(repo)
    
        issue_id = issue['number']
        filename = '%d.pdf' % issue_id
    
        self.debug('Create', 'Creating %s/%s/%s' % (user, repo, filename))
        
        title = issue['title']
        body = issue['body']
        name = issue['user']['login']
        number = issue['number']
        url = issue['html_url']
        avator_url = issue['user']['avatar_url']
        created_at = issue['created_at']

        td = datetime.timedelta(hours=9)
        created_at = datetime.datetime.strptime(created_at,
                                                '%Y-%m-%dT%H:%M:%SZ') + td

        if body == '':
            os.chdir('..%s..%s..' % (os.sep, os.sep))

            return

        body = 'Date : %s\n\n%s' % (created_at, body)

        wrap_body = wrap.wrap(body, 39)
        wrap_title = wrap.wrap(title, 39)

        row =  wrap_body.count('\n') + wrap_title.count('\n')
        height = 350 + row * 12

        c = canvas.Canvas(filename, pagesize=(220, height))
        pdfmetrics.registerFont(FONT)

        c.drawImage('..%s..%slogo.png' % (os.sep, os.sep),
                    60, height-110,
                    100, 100,
                    mask='auto', preserveAspectRatio=True)

        c.drawImage(avator_url.encode('UTF-8'),
                    10, height-195,
                    50, 50,
                    mask='auto', preserveAspectRatio=True)

        c.setFont(FONT_NAME, 10)
        t = c.beginText(10, height-110)
        t.textLines('Account: %s' % user)
        c.drawText(t)

        t = c.beginText(10, height-125)
        t.textLines('Project: %s' % repo)
        c.drawText(t)

        c.line(10, height - 135, 210, height - 135)

        c.setFont(FONT_NAME, 15)
        t = c.beginText(70, height-188)
        t.textLines(name)
        c.drawText(t)

        c.setFont(FONT_NAME, 20)
        t = c.beginText(70, height-168)
        t.textLines('Issue #%s' % number)
        c.drawText(t)

        c.line(10, height - 205, 210, height - 205)

        c.setFont(FONT_NAME, 10)

        t = c.beginText(10, height-225)
        t.textLines(wrap_title)
        c.drawText(t)

        _height = wrap_title.count('\n') * 12 + 225
        c.line(10, height - _height, 210, height - _height)

        t = c.beginText(10, height - _height - 20)
        t.textLines(wrap_body.encode('utf-8'))
        c.drawText(t)

        qr_url = 'http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=%s' % url
        c.drawImage(qr_url.encode('UTF-8'),
                    60, 10,
                    100, 100,
                    mask='auto', preserveAspectRatio=True)

        c.showPage()
        c.save()

        os.chdir('..%s..%s..' % (os.sep, os.sep))
Esempio n. 15
0
 def test_three_words_after_first_space(self):
     self.assertEqual('word\nword\nword', wrap('word word word', 6))
Esempio n. 16
0
 def wrap(self, L_ion):
     wrap(
         L_ion,
         [[self.xlo, self.xhi], [self.ylo, self.yhi], [self.zlo, self.zhi]])
Esempio n. 17
0
 def connectionMade(self):
     if types.ClassType == type(self.controller):
         self._controller = wrap(self.controller(self))
     else:
         self._controller = wrap(self.controller())
     self._execute()
Esempio n. 18
0
 def test_string_smaller_than_col(self):
     self.assertEqual('ab', wrap('ab', 3))
Esempio n. 19
0
 def test_empty_string(self):
     self.assertEqual('', wrap('', 1))
Esempio n. 20
0
 def test_three_words_after_second_space(self):
     self.assertEqual('word word\nword', wrap('word word word', 10))
Esempio n. 21
0
 def test_string_without_spaces(self):
     self.assertEqual('ab\ncd', wrap('abcd', 2))
Esempio n. 22
0
 def __init__(self, stage, *trap):
     defer.Deferred.__init__(self)
     self._results = []
     self._stage = wrap(stage, *trap)
     self._execute()
Esempio n. 23
0
 def __init__(self, source, *trap):
     Stage.__init__(self, *trap)
     self._source = wrap(source)
Esempio n. 24
0
 def test_after_word_boundary(self):
     self.assertEqual('word\nword', wrap('word word', 6))
Esempio n. 25
0
 def __init__(self, source, *trap):
     Stage.__init__(self, *trap)
     self._source = wrap(source)
Esempio n. 26
0
    status.push("request from %s" % user.login)
    r = request.parse_request(body)
    if r.kind == 'group':
        handle_group(r, user)
    elif r.kind == 'notification':
        handle_notification(r, user)
    else:
        msg = "%s: don't know how to handle requests of this kind '%s'" \
                        % (user.get_login(), r.kind)
        log.alert(msg)
        m = user.message_to()
        m.set_headers(subject = "unknown request")
        m.write_line(msg)
        m.send()
    status.pop()
    return True

def handle_request_main(req, filename = None):
    acl.try_reload()
    init_conf("src")
    status.push("handling email request")
    ret = handle_request(req, filename = filename)
    status.pop()
    return ret

def main():
    sys.exit(not handle_request_main(sys.stdin.read()))

if __name__ == '__main__':
    wrap.wrap(main)
Esempio n. 27
0
def clean(comment):
    """prepare comment field for printing"""
    comment = comment.replace('\\', '')
    comment = wrap(comment, 70)
    return comment
Esempio n. 28
0
 def __init__(self, stage, *trap):
     Stage.__init__(self)
     self._stage = wrap(stage, *trap)
     self.block = time.sleep
Esempio n. 29
0
 def __init__(self, stage, *trap):
     Stage.__init__(self)
     self._stage = wrap(stage,*trap)
     self.block = time.sleep
Esempio n. 30
0
 def __init__(self, stage, *trap):
     defer.Deferred.__init__(self)
     self._results = []
     self._stage = wrap(stage, *trap)
     self._execute()
Esempio n. 31
0
from machine import Pin, PWM

s1 = PWM(Pin(0), freq=50, duty=77)
s2 = PWM(Pin(2), freq=50, duty=77)


@subscribe('servo_1')
def on_servo_1(message):
    print(message)

    try:
        s1.duty(int(message))
    except Exception as e:
        print(e)


@subscribe('servo_2')
def on_servo_2(message):
    print(message)
    try:
        s2.duty(int(message))
    except:
        pass


async def main():
    pass


wrap(main, "config.json")
Esempio n. 32
0
                graph.add(frozenset([x,y]))

#output string
s = ""

ringpositions = rp.RingPositions(rings, coord, box)
ringsetpositions = rp.RingPositions(ringsets, ringpositions, box)
            

#network
if shownet:
    s += yp.Color(0)
    s += yp.Layer(1)
    for edge in graph:
        i,j = edge
        ci = wr.wrap(coord[i],box)
        cj = wr.wrap(coord[j]-ci,box) + ci
        s += yp.Line(ci,cj)


#Adjacency Graph
if adjacency:
    #First layer is reserved for adjacency graph
    s += yp.Color(0) #black
    s += yp.Layer(1)
    #in case kinds are specified, prepare the layer order
    order = 0
    orderdict = dict()
    for i in kinds:
        if not orderdict.has_key((i,i)):
            orderdict[(i,i)] = order