예제 #1
0
    def parse_number(self, s):  #{
        """
        '0.0000' -> 0
        '-1.000' -> -1
        '-5.124' -> Decimal('-5.124')
        '1.1.12' -> '1.1.12'
        """
        num = s

        if (num.count('.') == 1):  #{
            # Check if we can round it
            p = num.partition('.')
            if (int(p[2]) == 0):  #{
                num = int(p[0])
            #}
            else:  #{
                num = Decimal(num)
            #}
        #}
        elif (num.count('.') > 1):  #{
            # Possibly a dummy date like 1.1.1, just return
            pass
        #}
        else:  #{
            try:
                num = int(num)
            except ValueError:
                num = s
        #}
        return num
예제 #2
0
파일: base.py 프로젝트: paimoe/eu4map
    def parse_number(self, s):
        """
        '0.0000' -> 0
        '-1.000' -> -1
        '-5.124' -> Decimal('-5.124')
        '1.1.12' -> '1.1.12'
        """
        num = s

        if num.count('.') == 1:
            # Check if we can round it
            p = num.partition('.')
            if int(p[2]) == 0:
                num = int(p[0])
            else:
                num = Decimal(num)
        elif num.count('.') > 1:
            # Possibly a dummy date like 1.1.1, just return
            pass
        else:
            try:
                num = int(num)
            except ValueError:
                num = s
        return num
예제 #3
0
 def pull_video(self, server):
     url = server.youtube_db_path
     if url is None:
         return
     data = requests.get(url).text
     for line in data.split('\n'):
         if line:
             map_name, time, youtube_id, nickname = line.split(' - ', 4)
             if time.count('.') == 1:
                 time = Decimal(time)
             elif time.count('.') == 2:
                 mins, seconds = time.split('.', 1)
                 time = Decimal(mins) * 60 + Decimal(seconds)
             else:
                 print('WRONG VIDEO TIME', time)
                 continue
             try:
                 record = XDFTimeRecord.get(
                     XDFTimeRecord.map == map_name,
                     XDFTimeRecord.server == server,
                     XDFTimeRecord.time == Decimal(time))
             except DoesNotExist:
                 print(
                     'WARNING: existing youtube vid for non-existent record',
                     map_name, time, youtube_id)
                 continue
             video_url = 'https://youtu.be/{}'.format(youtube_id)
             if record.video_url == video_url:
                 continue
             XDFTimeRecord.update(video_url=None).where(
                 XDFTimeRecord.map == map_name,
                 XDFTimeRecord.server == server).execute()
             record.video_url = video_url
             record.save()
예제 #4
0
from decimal import Decimal as d
from fractions import Fraction as f
from sys import stdin
s = stdin.readline
t = ''
r = ''
u = []
d = []
for i in range(int(s())):
    a = s().strip().split('/')
    if d.count(int(a[0])) == 0:
        u += [int(a[0])]
    else:
        d.pop(int(a[0]))
    if u.count(int(a[1])) == 0:
        d += [int(a[1])]
    else:
        u.pop(int(a[1]))
a, b = 1, 1
for _ in u:
    a *= _
for _ in d:
    b *= _
print(f(a, b))

#n=int(s());r=s().strip()
#for i in range(n-1):
#    r='('+r+'*'+s().strip()+')'
#print(r)
#print(f(d(eval(r))))
#print(eval(r))