Example #1
0
 def handleRule(self, rule, params, paramDict):
     if(rule[0].lower()=="forget"):
         self.forget(params[0]) #Works only for one param
     if(rule[0].lower()=="response"):
         print(self.responseHandler(rule[1], params))
     if (rule[0].lower() == "learn"):
         if params.__len__() < 1:
             print("Invalid Number of Parameters: Illegal Operation")
         else:
             self.learn(params[0], params[1])
     if(rule[0].lower()=="action"):
         if(rule[1].lower()=="multiply" or rule[1].lower()=="sum" or rule[1].lower() == "subtract" or rule[1].lower() == "divide" or rule[1].lower() == "modulo" or rule[1].lower() == "power"):
             if params.__len__() < 2:
                 print("Invalid Number of Parameters: Illegal Operation")
             else:
                 #WARNING: maybe will also have to verify that we have the correct ammount of arguments?
                 #tho maybe that should be verified in the yacc. we'll see.
                 #print(params)
                 if not(self.RepresentsInt(params[0]) and self.RepresentsInt(params[1])):
                     print("Illegal Argument Type")
                 else:
                     numb1 = int(params[0])
                     numb2 = int(params[1])
                     if(rule[1].lower()=="sum"):
                         print("The result is "+str(Actions.Sum(numb1, numb2)))
                     elif(rule[1].lower() == "subtract"):
                         print("The result is "+str(Actions.Substract(numb1, numb2)))
                     elif (rule[1].lower() == "multiply"):
                         print("The result is " + str(Actions.Multiply(numb1, numb2)))
                     elif (rule[1].lower() == "divide"):
                         print("The result is " + str(Actions.Divide(numb1, numb2)))
                     elif (rule[1].lower() == "modulo"):
                         print("The result is " + str(Actions.Modulo(numb1, numb2)))
                     elif (rule[1].lower() == "power"):
                         print("The result is " + str(Actions.Power(numb1, numb2)))
     if (rule[1].lower() == "rolldice"):
         print("Your dice roll resulted in "+str(Actions.RollDice()))
     if (rule[1].lower() == "root"):
         if params.__len__()<1:
             print("Invalid Number of Parameters: Illegal Operation")
         else:
             if not (self.RepresentsInt(params[0])):
                 print("Illegal Argument Type")
             else:
                 numb1 = int(params[0])
                 print("The result is " + str(Actions.Root(numb1)))
     if (rule[1].lower() == "joke"):
         print(str (Actions.Joke()))
     if (rule[1].lower() == "random"):
         print("You got a "+str(Actions.Random()))
Example #2
0
def renameId(args):
    inpFiles = glob.glob(g_args.input)
    totalRenamedPoints = 0
    totalIdsChanged = 0
    fCount = 0

    for inpName in inpFiles:
        fHandler = Actions.FileHandler(inpName)
        pointInFileChanged = 0
        idsInFileChanged = 0
        for namespace in args.namespace:
            pointCount, idCount = fHandler.Rename_Id(namespace, args.id,
                                                     args.new)
            pointInFileChanged += pointCount
            idsInFileChanged += idCount

        targetFn = GetTargetFileName(inpName, g_args.output)
        fHandler.writeFile(targetFn, g_args.overwrite)
        Log.getLogger().info("{} IDs, {} dataponts renamed in {}".format(
            idsInFileChanged, pointInFileChanged, inpName))
        totalRenamedPoints += pointInFileChanged
        totalIdsChanged += idsInFileChanged
        if idsInFileChanged > 0:
            fCount += 1

    Log.getLogger().info("Renamed {} ids in {} files, {} datapoints".format(
        totalIdsChanged, fCount, totalRenamedPoints))
Example #3
0
def copyNamespace(args):
    inpFiles = glob.glob(g_args.input)
    totalCopied = 0
    fCount = 0

    for inpName in inpFiles:
        fHandler = Actions.FileHandler(inpName)
        copiedInFileCount = 0
        for namespace in args.namespace:
            copiedInFileCount += fHandler.Copy_Namespace(namespace, args.new)

        targetFn = GetTargetFileName(inpName, g_args.output)
        fHandler.writeFile(targetFn, g_args.overwrite)
        Log.getLogger().info("{} namespaces copied in {}".format(
            copiedInFileCount, inpName))
        totalCopied += copiedInFileCount
        if copiedInFileCount > 0:
            fCount += 1

    Log.getLogger().info("Copied {} namespaces in {} files".format(
        totalCopied, fCount))
Example #4
0
def deleteId(args):
    inpFiles = glob.glob(g_args.input)
    totalDeleted = 0
    fCount = 0

    for inpName in inpFiles:
        fHandler = Actions.FileHandler(inpName)
        deletedFromFileCount = 0
        for namespace in args.namespace:
            deletedFromFileCount += fHandler.Delete_Id(namespace, args.id)

        targetFn = GetTargetFileName(inpName, g_args.output)
        fHandler.writeFile(targetFn, g_args.overwrite)
        Log.getLogger().info("{} datapoints deleted from {}".format(
            deletedFromFileCount, inpName))
        totalDeleted += deletedFromFileCount
        if deletedFromFileCount > 0:
            fCount += 1

    Log.getLogger().info("Deleted {} datapoints  from {} files".format(
        totalDeleted, fCount))
Example #5
0
def deltaId(args):
    inpFiles = glob.glob(g_args.input)
    totalModified = 0
    fCount = 0

    for inpName in inpFiles:
        fHandler = Actions.FileHandler(inpName)
        modifiedFromFileCount = 0
        for namespace in args.namespace:
            modifiedFromFileCount = fHandler.ApplyDelta_Id(
                namespace, args.id, args.delta)

        targetFn = GetTargetFileName(inpName, g_args.output)
        fHandler.writeFile(targetFn, g_args.overwrite)
        Log.getLogger().info("{} datapoints delta's from {}".format(
            modifiedFromFileCount, inpName))
        totalModified += modifiedFromFileCount
        if modifiedFromFileCount > 0:
            fCount += 1

    Log.getLogger().info("delta'd {} datapoints  from {} files".format(
        totalModified, fCount))
Example #6
0
def copyId(args):
    inpFiles = glob.glob(g_args.input)
    totalCopiedPoints = 0

    fCount = 0

    for inpName in inpFiles:
        fHandler = Actions.FileHandler(inpName)

        for namespace in args.namespace:
            pointsCopied = fHandler.Copy_Id(namespace, args.id,
                                            args.newNamespace, args.newId)

        targetFn = GetTargetFileName(inpName, g_args.output)
        fHandler.writeFile(targetFn, g_args.overwrite)
        Log.getLogger().info("{} dataponts copied in {}".format(
            pointsCopied, inpName))
        totalCopiedPoints += pointsCopied

        if pointsCopied > 0:
            fCount += 1

    Log.getLogger().info("Copied {} datapoints in {} files".format(
        totalCopiedPoints, fCount))