Example #1
0
 def load_line(self, line):
     """ 
     data_id|group_name
     """
     try:
         parts = line.split(' -> ')
         manufactured_component_str = parts[0].strip()
         manufactured_component_str_parts = manufactured_component_str.split('|') 
         manufactured_type_id = int(manufactured_component_str_parts[0])
         manufactured_type_name = manufactured_component_str_parts[1]
         manufactured_group_id = int(manufactured_component_str_parts[2])
         
         manufactured_component = Component(manufactured_type_name, manufactured_type_id, group_id=manufactured_group_id) 
         
         component_parts = parts[1].strip().split(' ')
         for component_str in component_parts:
             component_str_parts = component_str.split('|')
             
             component_type_id = int(component_str_parts[0])
             component_amount = float(component_str_parts[1])
             
             manufactured_component.components[component_type_id] = Component("", component_type_id, component_amount)
             
         self.data[manufactured_type_id] = manufactured_component
     except Exception, e:
         print "Load line failed on '" + line + "': " + str(e)
Example #2
0
    def __init__(self, *args, **kwds):
        Component.__init__(self, *args, **kwds)

        self.log("Active_tag", "initializing component", self.data.level)

        # Set up data structures
        self.tags = {}
        self.scan_tags()
        self.generated = False
Example #3
0
    def __init__(self, *args, **kwds):
        Component.__init__(self, *args, **kwds)

        self.siteroot = "http://masenf.com"
        self.rsstitle = "masenf.com > blog"
        self.rssfile = "output/feed.rss"
        self.rsspath = "/feed.rss"
        self.NUM_POSTS = 20
        self.PREVIEW_CHARS = 256
        self.output_rss(self.rssfile)
Example #4
0
    def __init__(self, *args, **kwds):
        Component.__init__(self, *args, **kwds)

        # add predefined rewrites
        self.rewrites = { '/?' : ('/home.html',''),
                            'blog/?' : ('/blog.html','[R]'),
                            'blog/tag/([\ a-zA-Z]+)' : ('/blog/tag/$1.html','[R]'),
                            'blog/archive/([0-9]{4})-([0-9]{2})/?' : ('/blog/archive/$1-$2.html','[R]'),
                            'blog/rss2/?' : ('/feed.rss','[R]') }
        self.index_permalinks()
        self.write_htaccess()
Example #5
0
 def __init__ (self, locations):
     operations.Operation.__init__ (self)
     Component.__init__ (self, None)
     self.savePlaylist = SavePlaylistRegistry (self)
     self.locations = locations
     self.__preferences = RecordingPreferences (locations)
     self.__running_ops = []
     
     self._music_file_patterns = {}
     self._playlist_file_patterns = {}
     self._music_file_filters = None
     self._playlist_file_filters = None
     self.register_music_file_pattern ("MPEG Audio Stream, Layer III", "*.mp3")
     self.register_music_file_pattern ("Ogg Vorbis Codec Compressed WAV File", "*.ogg")
     self.register_music_file_pattern ("Free Lossless Audio Codec", "*.flac")
     self.register_music_file_pattern ("PCM Wave audio", "*.wav")
 def __init__ (self, locations):
     operations.Operation.__init__ (self)
     Component.__init__ (self, None)
     self.savePlaylist = SavePlaylistRegistry (self)
     self.locations = locations
     self.__preferences = RecordingPreferences (locations)
     self.__running_ops = []
     
     self._music_file_patterns = {}
     self._playlist_file_patterns = {}
     self._music_file_filters = None
     self._playlist_file_filters = None
     self.register_music_file_pattern ("MPEG Audio Stream, Layer III", "*.mp3")
     self.register_music_file_pattern ("Ogg Vorbis Codec Compressed WAV File", "*.ogg")
     self.register_music_file_pattern ("Free Lossless Audio Codec", "*.flac")
     self.register_music_file_pattern ("PCM Wave audio", "*.wav")
Example #7
0
    def do_create(self, arg):
        """\nCreate a new component.
        
        create [name=<string>] [version=<string>] [category=<string>]

            name     = new component name. Default = New Component.
            version  = component version. Default = 1.0.
            category = component category. Default = User Component.
        """
        args = CREATION_ARGS.parse(arg)
        if args:
            comp = Component()
            comp.name = args.name
            comp.version = args.version
            comp.category = args.category
            self.write("New component created.\n")
            settings.active_component = comp
        else:
            self.stdout.write("*** Arguments extraction error, creation canceled.\n")
Example #8
0
    def dfs(self, start_node: Node, a_component: Component) -> None:

        self.set_discovered(start_node)

        # if protein, get a peptide list, if peptide get a protein list
        neighbour_list = self.node_dict.get(start_node)

        # for all neighbouring white node that is not deleted, explore them
        for current_neighbour in neighbour_list:
            if self.is_white(current_neighbour) \
                    and (current_neighbour.get_first_id()
                         not in self.node_to_delete):
                self.dfs(current_neighbour, a_component)

        self.set_explored(start_node)

        # after the nodes are blacken,
        # add the protein or peptide into the a_component
        # with its neighbours
        if isinstance(start_node, Protein):
            a_component.add_protein(start_node, neighbour_list)
        elif isinstance(start_node, Peptide):
            a_component.add_peptide(start_node, neighbour_list)
Example #9
0
def separate(protein_peptide_graph: Graph) -> List[Component]:
    # for all white peptide nodes, explore them
    component_list = []

    for node in protein_peptide_graph.node_dict.keys():

        # if it is white and not deleted
        if protein_peptide_graph.is_white(node) and \
                node.get_first_id() not in protein_peptide_graph.node_to_delete:

            a_component = Component()
            protein_peptide_graph.dfs(node, a_component)
            component_list.append(a_component)

    print("separated")
    return component_list
Example #10
0
def connected_components_segmentation(intermediate_global_mask):
    """
    :param intermediate_global_mask: black and white image
    :return: components
    """
    _, labeled_img = cv2.connectedComponentsWithAlgorithm(
        intermediate_global_mask, 8, cv2.CV_32S, cv2.CCL_GRANA)
    labels = np.unique(labeled_img)
    labels = labels[labels != 0]

    components = []

    for label in labels:
        mask = np.zeros_like(labeled_img, dtype=np.uint8)
        mask[labeled_img == label] = 255

        # Compute the convex hull
        if get_opencv_major_version(cv2.__version__) in ['2', '3']:
            mask, contours, _ = cv2.findContours(mask, cv2.RETR_TREE,
                                                 cv2.CHAIN_APPROX_SIMPLE)
        else:
            contours, _ = cv2.findContours(mask, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_SIMPLE)

        hull = []
        for cnt in contours:
            hull.append(cv2.convexHull(cnt, False))
        hull_mask = np.zeros((mask.shape[0], mask.shape[1]), dtype=np.uint8)
        for i in range(len(contours)):
            hull_mask = cv2.drawContours(hull_mask, hull, i, 255, -1, 8)

        single_component, flag = draw_border_for_picture_parts(hull_mask)

        _, connected_component, stats, _ = cv2.connectedComponentsWithStatsWithAlgorithm(
            single_component, 8, cv2.CV_32S, cv2.CCL_GRANA)
        valid_labels = np.argwhere(
            stats[:, cv2.CC_STAT_AREA] >= LABEL_AREA_THRESHOLD)
        if valid_labels[0] == 0:
            valid_labels = valid_labels[1:]
        for valid_label in valid_labels:
            component = Component(valid_label, connected_component,
                                  stats[valid_label], flag)
            components.append(component)

    components.sort(key=lambda x: x.area, reverse=True)
    return components
Example #11
0
    def __init__(self, board, network, scheduler):
        self.board = board
        self.scheduler = scheduler
        self.parts_initialized = False
        self.mac = network.mac
        self.data = {}
        self.mine = None
        self.version = "0.8.0"
        self.listeners = []
        self.read_cache()
        #        if (type(self.mine) is dict and "parts" in self.mine):
        #            ct.print_heading("initializing from cache")
        #            Part.init_parts(board, scheduler, self.mine["parts"])

        Component.setup_services(board, scheduler)
        if (type(self.mine) is dict and "components" in self.mine):
            ct.print_heading("initializing from cache")
            Component.netlist_from_config(self.mine["components"])
            Component.print_netlist()
        MQTT.subscribe(config_topic_base + self.mac + "/config", self.on_mqtt)
Example #12
0
 def __init__(self, *args, **kwds):
     Component.__init__(self, *args, **kwds)
     self.PREVIEW_CHARS = 512
     self.TEMPLATE = "post-short.tmpl.html"
     self.NUM_POSTS = 10
Example #13
0
import os
import sys
sys.path.append("../")
from components import addComponent, Component

# Add components in order of dependency.

addComponent(
    Component(name="jsoncpp",
              srcDir=os.environ["SOURCE_DIR"] + "/../3rd_party/jsoncpp"))

addComponent(Component(name="Logger", runTestsCmd="./LoggerTest"))

addComponent(Component(name="misc", runTestsCmd="./misctest"))

addComponent(
    Component(name="GlobalConfiguration",
              runTestsCmd="./GlobalConfigurationTest"))

addComponent(
    Component(name="ParkingDatabase", runTestsCmd="./ParkingDatabaseTest"))

addComponent(Component(name="CloudService", runTestsCmd="./CloudServiceTest"))

addComponent(Component(name="PriceProvider",
                       runTestsCmd="./PriceProviderTest"))

addComponent(Component(name="VerifyParking",
                       runTestsCmd="./VerifyParkingTest"))

addComponent(Component(name="BLEService", runTestsCmd="./BLEServiceTest"))
    def load_game(self):
        back = "./Dominion/card_back.png"
        path = lambda name: f"./Dominion/{name}.png"

        for i in range(60):
            component = Component(65, 95, front=path("copper"), back=back)
            component.order = i
            self.public_components.append(component)
        for i in range(40):
            component = Component(190, 95, front=path("silver"), back=back)
            component.order = i
            self.public_components.append(component)
        for i in range(30):
            component = Component(315, 95, front=path("gold"), back=back)
            component.order = i
            self.public_components.append(component)

        for i in range(8):
            component = Component(65, 280, front=path("estate"), back=back)
            component.order = i
            self.public_components.append(component)
        for i in range(8):
            component = Component(190, 280, front=path("duchy"), back=back)
            component.order = i
            self.public_components.append(component)
        for i in range(8):
            component = Component(315, 280, front=path("province"), back=back)
            component.order = i
            self.public_components.append(component)

        for i in range(10):
            component = Component(65, 465, front=path("curse"), back=back)
            component.order = i
            self.public_components.append(component)
        component = Component(315, 465, front=path("trash"), back=back)
        component.order = 0
        self.public_components.append(component)
Example #15
0
import sys
import os
sys.path.append("../")
from components import addComponent, Component

addComponent(
    Component(name="sqlite3",
              srcDir=os.environ["SOURCE_DIR"] + "/../3rd_party/sqlite3/src"))

from common_components import *

# Intel Edison specific components here:
Example #16
0
import urllib.parse
import json
from auth import *
from modules import *

warnings.filterwarnings("ignore")


def urlencode(str):
    return urllib.parse.quote(str)

def urldecode(str):
    return urllib.parse.unquote(str)

if __name__=='__main__':

    autho = tweepy.OAuthHandler(user[0], user[1])
    autho.set_access_token(user[2], user[3])
    api = tweepy.API(autho)
    co = Component(api)
    
    lines = sys.argv[0]
    lines = urldecode(lines)
    lines = lines.encode('utf-8').decode()
    
    tweets = co.search(query=lines,count=10)
    an= co.analysis(tweets) 
    
    print(json.dumps(an))

Example #17
0

def urlencode(str):
    return urllib.parse.quote(str)


def urldecode(str):
    return urllib.parse.unquote(str)


if __name__ == '__main__':

    autho = tweepy.OAuthHandler(user[0], user[1])
    autho.set_access_token(user[2], user[3])
    api = tweepy.API(autho)
    co_api = Component(api)

    query = sys.argv[1]
    query = urldecode(query)
    query = query.encode('utf-8').decode()

    if len(sys.argv) == 2:
        "guest"
        tweets = co_api.search(query)
    elif len(sys.argv) == 3:
        "client"
        since_id = sys.argv[2]
        tweets = update_tweets(query, co_api, since_id)

    an = co_api.analysis(tweets)
    def __init__ (self, application):
        gtk.Window.__init__ (self, gtk.WINDOW_TOPLEVEL)
        operations.Operation.__init__ (self)
        Component.__init__ (self, application)
            
        self.__application = application
        self.__masterer = AudioMastering ()
        # Variable related to this being an Operation
        self.__running = False
        self.connect ("show", self.__on_show)
        # We listen for GtkMusicList events
        self.music_list_widget.listeners.append (self)

        glade_file = os.path.join (constants.data_dir, "serpentine.glade")
        g = gtk.glade.XML (glade_file, "main_window_container")
        
        # Send glade to setup subcomponents
        for c in self._components:
            if hasattr (c, "_setup_glade"):
                c._setup_glade (g)

        self.add (g.get_widget ("main_window_container"))
        self.set_title ("Serpentine")
        self.set_default_size (450, 350)
        self.set_icon_name ("gnome-dev-cdrom-audio")
        
        
        # record button
        # setup record button
        self.__write_to_disc = MapProxy (dict(
            button = g.get_widget ("write_to_disc"),
            menu   = g.get_widget ("write_to_disc_mni")
        ))
        
        self.__write_to_disc.set_sensitive (False)
        self.__write_to_disc["button"].connect ("clicked", self.__on_write_files)
        self.__write_to_disc["menu"].connect ("activate", self.__on_write_files)
        
        # masterer widget
        box = self.get_child()
        self.music_list_widget.show()
        box.add (self.music_list_widget)
        
        # preferences
        g.get_widget ("preferences_mni").connect ("activate", self.__on_preferences)
        
        # setup remove buttons
        self.remove = MapProxy ({"menu": g.get_widget ("remove_mni"),
                                 "button": g.get_widget ("remove")})

        self.remove["menu"].connect ("activate", self.__on_remove_file)
        self.remove["button"].connect ("clicked", self.__on_remove_file)
        self.remove.set_sensitive (False)
        
        # setup clear buttons
        self.clear = MapProxy ({"menu": g.get_widget ("clear_mni"),
                                "button": g.get_widget ("clear")})
        self.clear["button"].connect ("clicked", self.clear_files)
        self.clear["menu"].connect ("activate", self.clear_files)
        self.clear.set_sensitive (False)
        
        # setup quit menu item
        g.get_widget ("quit_mni").connect ("activate", self.stop)
        self.connect("delete-event", self.stop)
        
        # About dialog
        g.get_widget ("about_mni").connect ("activate", self.__on_about)
        
        # update buttons
        self.on_contents_changed()
        
        if self.__application.preferences.drive is None:
            gtkutil.dialog_warn (
                _("No recording drive found"),
                _("No recording drive found on your system, therefore some of "
                  "Serpentine's functionalities will be disabled."),
                parent = self
            )
            g.get_widget ("preferences_mni").set_sensitive (False)
            self.__write_to_disc.set_sensitive (False)
    
        # Load internal XSPF playlist
        self.__load_playlist()
Example #19
0
def get_context():
    """Return the dictionnary containing the context of the exercise."""
    with open(sys.argv[1], "r") as f:
        context = json.load(f)
    Component.sync_context(context)
    return context
Example #20
0
    def _insert_entry_from_page_text(self, data_id, data_text):
        soup = BeautifulSoup(data_text)
        
        type_name = soup.find_all('h1')[0].string.encode('utf8')
        
        if 'Sorry' in [v.string for v in soup.find_all('h2')] or 'Error' in [v.string for v in soup.find_all('h1')]:
            # The item with this typeid does not exist!
            manufactured_component = Component(type_name, data_id)
            manufactured_component.components = {-1: Component("None", -1)}
            self.data[data_id] = manufactured_component
            return False
        
        group_id = -1
        
        # Let's try to decipher the group
        forms = soup.find_all('form')
        for form in forms:
            form_anchors = form.find_all('a')
            for anchor in form_anchors:
                if anchor.string == 'Browse Market Group':
                    group_url = anchor.get('href')
                    group_id = get_group_id_from_url(group_url)
                    self.groups.add_data(group_id)
                    
        volume = 9999999999
        
        # Let's try to decipher the volume
        forms = soup.find_all('form')
        for form in forms:
            if form.get('name') == 'type_add':
                dds = form.find_all('dd')
                mm_string = str(dds[1])
                mm_string = mm_string.replace('<dd>', '')
                mm_string = mm_string[0:mm_string.index('<sup>') - 1]
                volume = float(mm_string)
#            form_anchors = form.find_all('a')
#            for anchor in form_anchors:
#                if anchor.string == 'Browse Market Group':
#                    group_url = anchor.get('href')
#                    group_id = get_group_id_from_url(group_url)
#                    self.groups.add_data(group_id)
        
        manufactured_component = Component(type_name, data_id, 1, group_id=group_id, volume=volume)
        
        for_unit_count = 1
        
        manufacturing_specified = False
        reprocessing_specified = False
        
        for div in soup.find_all('div'):
            for c in div.contents:
                if c.name == 'h4' and c.string == 'Manufacturing':
                    # This should happen only once if there is a manufacturing bit
                    manufacturing_specified = True
                    for_unit_count = self._get_for_unit_count(div)
                    manufactured_component.components = self._get_components(div, for_unit_count)
                        
                if c.name == 'h4' and c.string == 'Reprocessing':
                    # This should happen only once if there is a reprocessing bit
                    reprocessing_specified = True
                    for_unit_count = self._get_for_unit_count(div)
                    manufactured_component.reprocessing = self._get_components(div, for_unit_count)
        
        if not manufacturing_specified:
            manufactured_component.components = {-1: Component("Empty", -1)}
            
        if not reprocessing_specified:
            manufactured_component.reprocessing = {-1: Component("Empty", -1)}

        self.data[data_id] = manufactured_component
        
        return True
    def __init__(self, application):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        operations.Operation.__init__(self)
        Component.__init__(self, application)

        self.__application = application
        self.__masterer = AudioMastering()
        # Variable related to this being an Operation
        self.__running = False
        self.connect("show", self.__on_show)
        # We listen for GtkMusicList events
        self.music_list_widget.listeners.append(self)

        glade_file = os.path.join(constants.data_dir, "serpentine.glade")
        g = gtk.glade.XML(glade_file, "main_window_container")

        # Send glade to setup subcomponents
        for c in self._components:
            if hasattr(c, "_setup_glade"):
                c._setup_glade(g)

        self.add(g.get_widget("main_window_container"))
        self.set_title("Serpentine")
        self.set_default_size(450, 350)
        self.set_icon_name("gnome-dev-cdrom-audio")

        # record button
        # setup record button
        self.__write_to_disc = MapProxy(
            dict(button=g.get_widget("write_to_disc"),
                 menu=g.get_widget("write_to_disc_mni")))

        self.__write_to_disc.set_sensitive(False)
        self.__write_to_disc["button"].connect("clicked",
                                               self.__on_write_files)
        self.__write_to_disc["menu"].connect("activate", self.__on_write_files)

        # masterer widget
        box = self.get_child()
        self.music_list_widget.show()
        box.add(self.music_list_widget)

        # preferences
        g.get_widget("preferences_mni").connect("activate",
                                                self.__on_preferences)

        # setup remove buttons
        self.remove = MapProxy({
            "menu": g.get_widget("remove_mni"),
            "button": g.get_widget("remove")
        })

        self.remove["menu"].connect("activate", self.__on_remove_file)
        self.remove["button"].connect("clicked", self.__on_remove_file)
        self.remove.set_sensitive(False)

        # setup clear buttons
        self.clear = MapProxy({
            "menu": g.get_widget("clear_mni"),
            "button": g.get_widget("clear")
        })
        self.clear["button"].connect("clicked", self.clear_files)
        self.clear["menu"].connect("activate", self.clear_files)
        self.clear.set_sensitive(False)

        # setup quit menu item
        g.get_widget("quit_mni").connect("activate", self.stop)
        self.connect("delete-event", self.stop)

        # About dialog
        g.get_widget("about_mni").connect("activate", self.__on_about)

        # update buttons
        self.on_contents_changed()

        if self.__application.preferences.drive is None:
            gtkutil.dialog_warn(
                _("No recording drive found"),
                _("No recording drive found on your system, therefore some of "
                  "Serpentine's functionalities will be disabled."), self)
            g.get_widget("preferences_mni").set_sensitive(False)
            self.__write_to_disc.set_sensitive(False)

        # Load internal XSPF playlist
        self.__load_playlist()
Example #22
0
#  Components
#
#########

if __name__ == '__main__':
    from components import DefraggingArrayComponent as Component
    import numpy as np

    #TODO tests should include: when there is nothing in the first class,
    # when there is nothing in the last class.  When there is nothing
    # in one or many in between classes.  When the allocation scheme has repeat
    # entries.  When the allocation scheme is not contiguous.  component
    # dimensions of (1,),(n,),(n,m) and when incorrect dimensions are added.
    # also, when components have complex data types (structs)

    d1 = Component('component_1', (1, ), np.int32)
    d2 = Component('component_2', (2, ), np.int32)
    d3 = Component('component_3', (3, ), np.int32)
    allocation_scheme = (
        (1, 1, 1),
        (1, 0, 1),
        (1, 0, 0),
    )

    allocator = GlobalAllocator([d1, d2, d3], allocation_scheme)

    to_add = []
    to_add.append({
        'component_1': 1,
        'component_3': (1, 2, 3),
        'component_2': ((1, 10), (2, 20)),
Example #23
0
@author: khalid
"""
from modules import *
import scrap
import statuslookup as sl
from components import Component
from auth import *


if __name__ == '__main__':
    '''handle maxtweet''' 
    
    autho = tweepy.OAuthHandler(user[0], user[1])
    autho.set_access_token(user[2], user[3])
    api = tweepy.API(autho)
    user_com = Component(api)
    
    num_tweets=1000

    search= sys.argv[1]
    if sys.argv[2] ==1:
        userName= 1
    elif sys.argv[2] ==2:
        query = 1
    else:
        print('error')

    #language= 'ar'
    start= '2019-{}-{}'
    
    intervals = [(start.format(f'{i%12:02}','01'),start.format(f'{(i+1)%12:02}','01'))for i in range(1,8)]
import sys
import os
sys.path.append("../")
from components import addComponent, Component

addComponent(
    Component(name="sqlite3",
              srcDir=os.environ["SOURCE_DIR"] + "/../3rd_party/sqlite3/src"))

addComponent(
    Component(name="openssl",
              srcDir=os.environ["SOURCE_DIR"] + "/../3rd_party/openssl"))

addComponent(
    Component(name="curl",
              srcDir=os.environ["SOURCE_DIR"] + "/../3rd_party/curl"))

exec('from common_components import *')

# Raspberry Pi specific components here: