Esempio n. 1
0
class ReadFileCSV:
    """
    @overview: it contains the properties in file INI
    """
    def __init__(self, new_dir):
        self.dir = new_dir
        self.log = PersonalLogging("ReadFileCSV", False)

    def read(self, name):
        path = "{0}{1}{2}".format(self.dir, os.sep, name)
        result = []
        exists = os.path.exists(path)
        if exists:  #TODO decorator
            with open(path, newline='') as csvfile:
                reader = csv.DictReader(csvfile)
                for row in reader:
                    result.append(ReadCSV(row))
        else:
            raise Exception(
                "The file [{0}] is not present, I stop the elaboration ".
                format(path))
        self.log.print("Elaborated file: {0}".format(len(result)))
        return result

    def __str__(self):
        return "ReadFileCSV:{0}".format(str(self.dir))

    def __repr__(self):
        return "ReadFileCSV:{0}".format(str(self.dir))
Esempio n. 2
0
class NameDraft:
    """
    @overview: class about the name of the file with selected tags
    """
    
    def __init__(self, new_directory):
        self.directory = new_directory
        self.logging = PersonalLogging("NameDraft")

    def name(self):
        """
        @return complete path of the file draft
        """    
        res = "{0}{1}{2}".format(self.directory , os.sep , "draft_tags.txt")
        self.logging.print("name:{0}".format(res))
        return res
Esempio n. 3
0
class GroupTags:
    '''@overview: it contains the tags with every rating
    '''
    def __init__(self, new_list):
        self.tags = new_list
        self.log = PersonalLogging("GroupTags")

    def mean(self):
        '''@return  the rating mean of the list of tags'''
        return sum(tmp.rating() for tmp in self.tags) / len(self.tags)

    def median(self):
        '''
        @return  the rating median of the list of tags
            from https://www.geeksforgeeks.org/finding-mean-median-mode-in-python-without-libraries/
        '''
        n_num = [tmp.rating() for tmp in self.tags]
        n_num.sort()
        number_element = len(n_num)
        if number_element % 2 == 0:
            median1 = n_num[number_element // 2]
            median2 = n_num[number_element // 2 - 1]
            median = (median1 + median2) / 2
        else:
            median = n_num[number_element // 2]
        return median

    def calculate(self):
        '''
        @return list of good tags to sell
        '''
        elements = [tmp.label() for tmp in self.tags]
        elements.sort()
        self.log.print("At beginning, there are {0} tags".format(
            len(elements)))
        mean = round(self.mean())
        choosen_tags = [tmp.name for tmp in self.tags if tmp.rating() > mean
                        ]  #filter only element with higher rating than mean
        return CorrectTags(choosen_tags).control()
Esempio n. 4
0
class Month:
    """ @overview this class has the dat aof year and month"""
    def __init__(self, newformattedtimestamp):
        self.timefile = newformattedtimestamp
        self.log = PersonalLogging("Month", False)

    def name(self):
        """@return creation month as string """
        date = self.timefile
        self.log.print("Month.show():" + str(date))
        tmp = date.split(" ")
        return self.timefile

    def single_number(self):
        """@return number of the month"""
        #TODO rename to 'number'
        translateMonths = {
            "Jan": "01",
            "Feb": "02",
            "Mar": "03",
            "Apr": "04",
            "May": "05",
            "Jun": "06",
            "Jul": "07",
            "Aug": "08",
            "Sep": "09",
            "Oct": "10",
            "Nov": "11",
            "Dec": "12"
        }
        return str(translateMonths[self.name()])

    def __eq__(self, other):
        return self.timefile == other.timefile

    def __repr__(self):
        return "Month[" + self.single_number() + "][" + self.name() + "]"
Esempio n. 5
0
 def __init__(self, new_directory, new_name_csv):
     self.logging = PersonalLogging("NameCSV")
     self.directory = new_directory
     self.namecsv = new_name_csv 
Esempio n. 6
0
 def __init__(self, new_dir):
     self.dir = new_dir
     self.log = PersonalLogging("ReadFileCSV", False)
Esempio n. 7
0
 def __init__(self, new_read_file_csv):
     self.read_file_csv = new_read_file_csv
     self.log = PersonalLogging("Video")
Esempio n. 8
0
 def __init__(self, new_row):
     self.manual_tag = new_row
     self.log = PersonalLogging("Keyword")
Esempio n. 9
0
 def __init__(self, newini, newcsv):
     self.log = PersonalLogging("CSVVideo")
     self.ini = newini
     self.manualcsv = newcsv
     self.staticcsv = CSVVideoStatic()
Esempio n. 10
0
class Control:
    '''
    @overview the class control the params
    '''
    def __init__(self, new_args):
        self.arguments = new_args
        self.log = PersonalLogging("Control", True)

    def act(self):
        '''
        @return true if the paramers are correct
        '''
        var = None
        opts = [opt for opt in self.arguments[1:] if opt.startswith("-")]
        args = [arg for arg in self.arguments[1:] if not arg.startswith("-")]
        print("opts:" +  str(opts))
        print("args: " + str(args))
        if 0 == len(opts):
            self.log.warn("Mandatory flas:\n-c(copy the file from source dir to target dir);\n-w(rite) the file CSV and INI in one dir;\n -j(oin) the CSV and INI files in one in one dir")
            self.log.warn("Exit program")
        if "-c" in opts:
            self.log.print("Copy(" + str(args) +")")
            var = Copy(args)
        elif "-w" in opts:
            self.log.print("Write")
            var = Write(args)
        elif "-j" in opts:
            self.log.print("Join")
            var = Join(args) 
        elif "-l" in opts:
            self.log.print("List")
            var = ListTag(args) 
        else:
            self.log.warn("The flag [{0}] is unkown".format (opts) )

        return var
Esempio n. 11
0
 def __init__(self, newextension):
     self.extension = newextension
     self.log = PersonalLogging("Media", False)
Esempio n. 12
0
 def __init__(self, new_args):
     self.arguments = new_args
     self.log = PersonalLogging("Control", True)
Esempio n. 13
0
 def __init__(self, new_safe_file):
     self.safefile = new_safe_file
     self.logging = PersonalLogging("ManualDataCSV")
Esempio n. 14
0
 def __init__(self, new_list):
     self.tags = new_list
     self.log = PersonalLogging("GroupTags")
Esempio n. 15
0
 def __init__(self, new_directory):
     self.directory = new_directory
     self.logging = PersonalLogging("NameINI")
Esempio n. 16
0
 def __init__(self, newformattedtimestamp):
     self.timefile = newformattedtimestamp
     self.log = PersonalLogging("Month", False)
Esempio n. 17
0
 def __init__(self, new_extension):
     self.ext = new_extension
     self.log = PersonalLogging("Extension", True)
Esempio n. 18
0
 def __init__(self, new_dir):
     self.dir = new_dir
     self.log = PersonalLogging("ReadFileTag")