Пример #1
0
def test():
    with open(data_path('lenses.txt')) as f:
        lenses = [x.strip().split('\t') for x in f]
    lenses_labels = ['age', 'prescript', 'astigmatic', 'tear rate']
    tree = create_tree(lenses, lenses_labels)
    print tree
    create_plot(tree, name='lenses tree')
Пример #2
0
    def paint(self, evt):
        dc = wx.PaintDC(self)

        # background
        dc.SetBackground(wx.Brush("#e2e2e2"))
        dc.Clear()

        # shadow
        w, h = self.GetSize()
        dc.GradientFillLinear((0, h - 10, w, h), '#4d7685', "#e2e2e2",
                              wx.NORTH)

        # title
        dc.SetTextForeground('#4d7685')
        dc.SetFont(wx.Font(66, wx.FONTFAMILY_SWISS, wx.NORMAL, wx.LIGHT,
                           False))
        dc.DrawText("FreshPass", 65, 8)

        # icon
        with open(data_path(
                'resources/icon.iconset/icon_128x128.png')) as icon_file:
            image = wx.ImageFromStream(icon_file, wx.BITMAP_TYPE_PNG)
        image = image.Scale(64, 64, wx.IMAGE_QUALITY_HIGH)
        bitmap = wx.BitmapFromImage(image)
        if "gtk1" in wx.PlatformInfo:
            # via wxPython ImageAlpha demo -- fake alpha for wxGTK (gtk+ 1.2)
            img = bitmap.ConvertToImage()
            img.ConvertAlphaToMask(220)
            bitmap = img.ConvertToBitmap()
        dc.DrawBitmap(bitmap, 2, 5, True)
Пример #3
0
    def paint(self, evt):
        dc = wx.PaintDC(self)

        # background
        dc.SetBackground(wx.Brush("#e2e2e2"))
        dc.Clear()

        # shadow
        w, h = self.GetSize()
        dc.GradientFillLinear((0, h-10, w, h), '#4d7685', "#e2e2e2", wx.NORTH)

        # title
        dc.SetTextForeground('#4d7685')
        dc.SetFont(wx.Font(66, wx.FONTFAMILY_SWISS, wx.NORMAL, wx.LIGHT, False))
        dc.DrawText("FreshPass",
                    65, 8)

        # icon
        with open(data_path('resources/icon.iconset/icon_128x128.png')) as icon_file:
            image = wx.ImageFromStream(icon_file, wx.BITMAP_TYPE_PNG)
        image = image.Scale(64, 64, wx.IMAGE_QUALITY_HIGH)
        bitmap = wx.BitmapFromImage(image)
        if "gtk1" in wx.PlatformInfo:
            # via wxPython ImageAlpha demo -- fake alpha for wxGTK (gtk+ 1.2)
            img = bitmap.ConvertToImage()
            img.ConvertAlphaToMask(220)
            bitmap = img.ConvertToBitmap()
        dc.DrawBitmap(bitmap, 2, 5, True)
Пример #4
0
 def add_controls(self):
     w, h = GlobalState.controller.frame.GetSize()
     gif = wx.animate.GIFAnimationCtrl(self,
                                       -1,
                                       data_path('resources/loader.gif'),
                                       pos=(w / 2 - 16 - 70, h / 2 - 16))
     gif.GetPlayer().UseBackgroundColour(True)
     gif.Play()
Пример #5
0
 def load_rules(cls):
     # load yaml files from rules/ dir
     rules = []
     for subdir, dirs, files in os.walk(data_path('rules')):
         for file in files:
             if file.endswith('.yaml'):
                 with open(os.path.join(subdir, file), 'rb') as f:
                     rules.append(Rule(**dict(yaml.load(f), file_name=file)))
     return rules
Пример #6
0
 def load_rules(cls):
     # load yaml files from rules/ dir
     rules = []
     for subdir, dirs, files in os.walk(data_path('rules')):
         for file in files:
             if file.endswith('.yaml'):
                 with open(os.path.join(subdir, file), 'rb') as f:
                     rules.append(
                         Rule(**dict(yaml.load(f), file_name=file)))
     return rules
Пример #7
0
def over_files(dir_relative_path):
    dirpath = data_path(dir_relative_path)
    filenames = listdir(dirpath)
    m = len(filenames)

    def generator():
        for i in xrange(m):
            filename = filenames[i]
            name, ext = path.splitext(filename)
            class_num = int(name.split('_')[0])
            data = import_image(path.join(dirpath, filename))
            yield i, class_num, data

    return m, generator()
Пример #8
0
def get_browser(javascript_enabled=True):
    desired_capabilities = dict(DesiredCapabilities.PHANTOMJS)
    # use Chrome user agent so sites serve the same content we see in Selenium IDE
    desired_capabilities["phantomjs.page.settings.userAgent"] = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36"
    desired_capabilities["phantomjs.page.settings.javascriptEnabled"] = javascript_enabled
    driver = webdriver.PhantomJS(
        executable_path=data_path('contrib/phantomjs'),
        desired_capabilities=desired_capabilities,
        service_log_path='phantomjs.log' if GlobalState.options.debug else os.devnull,
        )
    driver.implicitly_wait(get_default_timeout())
    driver.set_window_size(*WINDOW_SIZE)

    # make sure that phantomjs process is terminated when we exit
    GlobalState.cleanup_message.send({'action':'kill','pid':driver.service.process.pid})

    return driver
Пример #9
0
def classify_person():
    filepath = data_path('datingTestSet2.txt')
    result_list = ['not at all', 'in small doses', 'in large doses']
    play_games = float(raw_input(
        'percentage of time spent playing video games? '
    ))
    ff_miles = float(raw_input(
        'frequent flier miles earned per year? '
    ))
    ice_cream = float(raw_input(
        'liters of ice cream consumed per year? '
    ))

    data_set, labels = import_dataset(filepath)
    norm_data_set, ranges, min_vals = normalize(data_set)
    data = array([ff_miles, play_games, ice_cream])
    norm_data = (data - min_vals) / ranges
    result = classify(norm_data, norm_data_set, labels, 7)

    print 'you will probably like this person: {}'.format(
        result_list[result - 1]
    )
Пример #10
0
def get_browser(javascript_enabled=True):
    desired_capabilities = dict(DesiredCapabilities.PHANTOMJS)
    # use Chrome user agent so sites serve the same content we see in Selenium IDE
    desired_capabilities[
        "phantomjs.page.settings.userAgent"] = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36"
    desired_capabilities[
        "phantomjs.page.settings.javascriptEnabled"] = javascript_enabled
    driver = webdriver.PhantomJS(
        executable_path=data_path('contrib/phantomjs'),
        desired_capabilities=desired_capabilities,
        service_log_path='phantomjs.log'
        if GlobalState.options.debug else os.devnull,
    )
    driver.implicitly_wait(get_default_timeout())
    driver.set_window_size(*WINDOW_SIZE)

    # make sure that phantomjs process is terminated when we exit
    GlobalState.cleanup_message.send({
        'action': 'kill',
        'pid': driver.service.process.pid
    })

    return driver
Пример #11
0
def test_dating_set():
    ho_ratio = 0.1
    filepath = data_path('datingTestSet2.txt')
    data_set, labels = import_dataset(filepath)
    norm_data_set, ranges, min_vals = normalize(data_set)
    m = norm_data_set.shape[0]
    num_test = int(m * ho_ratio)
    error_count = 0.0

    for i in range(num_test):
        classifier_result = classify(
            norm_data_set[i, :],
            norm_data_set[num_test:m, :],
            labels[num_test:m],
            7
        )
        if classifier_result != labels[i]:
            error_count += 1.0

    print 'the total error rate is: %f' % (error_count / num_test)

    colors = []
    sizes = 15.0 * array(labels)

    for label in labels:
        if label == 1:
            color = 'red'
        elif label == 2:
            color = 'green'
        elif label == 3:
            color = 'blue'
        else:
            color = 'gray'

        colors.append(color)

    _fig = plt.figure()
    _ax = _fig.add_subplot(111)
    type1 = _ax.scatter([-10], [-10], s=15, c='red')
    type2 = _ax.scatter([-10], [-15], s=30, c='green')
    type3 = _ax.scatter([-10], [-20], s=45, c='blue')

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(data_set[:, 0], data_set[:, 1], c=colors, s=sizes)
    ax.set_xlabel('Frequent Flyier Miles Earned Per Year')
    ax.set_ylabel('Percentage of Time Spent Playing Video Games')

    ax.legend(
        [type1, type2, type3],
        ['Did Not Like', 'Liked in Small Doses', 'Liked in Large Doses'],
        loc=2
    )
    ax.grid(True)

    fig.savefig(data_out_path('games_vs_miles.png'))

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(data_set[:, 1], data_set[:, 2], c=colors, s=sizes)
    ax.set_xlabel('Percentage of Time Spent Playing Video Games')
    ax.set_ylabel('Liters of Ice Cream Consumed Per Week')
    ax.legend(
        [type1, type2, type3],
        ['Did Not Like', 'Liked in Small Doses', 'Liked in Large Doses'],
        loc=4
    )
    ax.grid(True)
    fig.savefig(data_out_path('ice_cream_vs_games.png'))
def out_path(table):
    return helpers.data_path("out_" + table + ".csv")
def in_path(table):
    return helpers.data_path("in_" + table + ".csv")