Ejemplo n.º 1
0
 def __init__(self, interval, paraengine_sdk_folder, paraengine_git_folder,
              app_bits, callback):
     pass
     self.interval = interval
     self.paraengine_sdk_folder = paraengine_sdk_folder
     self.paraengine_git_folder = paraengine_git_folder
     self.app_bits = app_bits
     self.callback = callback
     self.pkg_txt_file_path = self.paraengine_sdk_folder + "/pkg_file.txt"
     self.zip_file_path = self.paraengine_sdk_folder + "/installer/main_full_mobile.zip"
     self.pkg_file_path = "%s/installer/main_full_mobile.pkg" % self.paraengine_sdk_folder
     self.pkg_txt_timer = PerpetualTimer(interval, self.CheckPkgTxtFile)
     self.pkg_timer = PerpetualTimer(interval, self.CheckPkgFile)
Ejemplo n.º 2
0

def owl_timer_tick():
    """
    Понижает уровень счастья и сытости у сов
    """
    for owl in owls:
        owl.happiness_down()
        owl.satiety_down()
        # print(f'{owl.name} \t {owl.happiness_lvl} \t {owl.satiety_lvl}')
        if owl.dead:
            owls.remove(owl)
            print(f'Сова {owl.name} мертва')


owl_timer = PerpetualTimer(30, owl_timer_tick)
mouse_timer = PerpetualTimer(1, mouse_timer_tick)


def intersection_lists(l1, l2):
    """
    Возвращает пересечение списков l1 & l2
    """
    result = []
    for i in l1:
        for j in l2:
            if i == j:
                result.append(i)
    return result

class OperationCenter:
    __instance = None
    perpetualTimerSellBreachWatch = PerpetualTimer()

    def __new__(self):
        if self.__instance == None:
            self.__instance = object.__new__(self)
            self.__instance.name = ''
        self.list_chosen_data_managers = []
        self.chosen_stock_temp_container = []
        self.listGoldenGeese = []
        self.nodeRequester = NodeRequester()
        self.dataFilterManager = DataFilterManager()
        self.dynamicTimeMarkationManager = DynamicTimeMarkationManager()
        self.timeManager = TimeManager()
        self.dynamaTransit = DynamaTransit()
        self.typeConverter = TypeConverter()

        self.httpUtility = HTTPUtility()
        self.isHoldings = "0"
        self.boughtStockSymbol = "JKJKJKJK"
        self.isSellDelimiterMet = "0"
        return self.__instance

    def process_main_process_loop(self):
        self.main_process_loop()

    def main_process_loop(self):
        self.perpetual_timer.setup_timer_stock(1, 1000000, self.main_loop,
                                               'main_process_loop')

    def main_loop(self):
        #Handle loop, check time, if time 10:30 initiate time process.
        if (self.calculate_time_delimiter_initiate_buy_process()):
            self.initiate_buy_process()

    def calculate_time_delimiter_initiate_buy_process(self):
        print(self.time_manager.get_current_hour())
        if (self.time_manager.get_current_hour() == self.scrape_hour):
            if (self.time_manager.get_current_minute() == self.scrape_minute):
                return True
        return False

    def breachSellHoldings(self, holdings):
        #Verify that holdings have been sold
        listResults = self.typeConverter.parseHoldingQueryString(holdings)
        quantityOfShares = listResults[1]

        #if listResults
        if (quantityOfShares != 0):
            print("canceling perpetualTimerSellBreachWatch")
            self.perpetualTimerSellBreachWatch.cancel()

    def breachBuy(self, stringQuery):
        print(stringQuery)
        #totalsecurities
        #after purchase and wait 10 seconds, holdings string
        listResults = self.typeConverter.parseHoldingQueryString(stringQuery)
        quantityOfShares = listResults[1]

        # amountOfShares
        print("quantityOfShares: " + quantityOfShares)
        if (quantityOfShares != "0"):
            self.isHoldings = "1"

        #if positions found, continue operations - breach sell.
        if (self.isHoldings == "1"):
            print("isHoldings: true")
            #Continue operations
            self.quantityOfShares = quantityOfShares
            self.totalSecurities = listResults[0]
            print(self.quantityOfShares + " " + self.totalSecurities)

            #set monitor stocks on loop, for sell process
            #handle looped query, get latest stock from node
            self.initiateSellBreachProcess()

        #else cancel operations.
        else:
            print("cancel operations")
            #Support for reiterate chosen process

    def initiateSellBreachProcess(self):
        print("begin sell process")
        self.perpetualTimerSellBreachWatch.setup_timer_stock(
            1, 3000, self.getStockInformation, 'getStockInformation')

    def getStockInformation(self):
        print("getting stock")
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        response = loop.run_until_complete(
            self.httpUtility.async_get_stock_query("VICI"))

        listResults = self.typeConverter.parseBreachStockQueryString(response)
        # print(listResults[0] + " " + listResults[1] + " " + listResults[2] + " " + listResults[3] + " " + listResults[4])

        #test boughtPrice
        boughtPrice = 29.72
        self.checkDelimiterMet(listResults, boughtPrice)

    def checkDelimiterMet(self, listResults, delimiter):
        #Current bought
        #listResults = [pchg, pcls, last, bid, ask]
        #delimiter met do sell
        if (listResults[2] == delimiter and self.isSellDelimiterMet == "0"):
            print("DELIMITER MET")
            #Sell post
            self.isSellDelimiterMet = "1"
            self.sellPost(self.boughtStockSymbol)

    def sellPost(self, symbol):
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        response = loop.run_until_complete(
            self.httpUtility.async_breach_sell(symbol))

    def initiate_buy_process(self):
        #Buy trade process
        #Bird to node
        self.nodeRequester.postBuyBreachWatch()

    def goldenGooseProcess(self, data):
        listGeeseMetrics = []
        # for key, value in data.items():
        #     listGeeseMetrics.append(value)
        for gooseMetrics in data:
            listGeeseMetrics.append(gooseMetrics)

        print("list symbol values: " + str(listGeeseMetrics))

        # intake stock json, take price and pchg
        # transform json into list, of price and pchg.
        # get price and pchg of each item in list.
        #parse json of each in list

        self.dynamaTransit.goldenGooseProcessIntake(self, listGeeseMetrics)

    def getNodeInformation(self, caseCalculationType):
        scenarioManager = ScenarioManager()
        # response = self.nodeRequester.getAllRecordSets("02/08/2019")
        response = self.nodeRequester.getAllRecordSets("02/21/2019")
        dayList = self.dataFilterManager.createListOfDaylists(response)
        observanceObjectResultsComposite = []
        stockEntryTotalitiesList = []
        for day in dayList[0]:
            stockEntryTotalitiesList.append(
                self.dataFilterManager.generateStockEntryTotalities(day))
        # print(len(stockEntryTotalitiesList))

        if (caseCalculationType == 0):
            for stockEntryTotalities in stockEntryTotalitiesList:
                fullRangeStockList = self.dynamicTimeMarkationManager.calculateFullRangeList(
                    stockEntryTotalities)
                observanceObjectResult = scenarioManager.calculateFullRangeResults(
                    fullRangeStockList)
                observanceObjectResultsComposite.append(observanceObjectResult)

            for observanceObjectResult in observanceObjectResultsComposite:
                print(observanceObjectResult.getScenarioOutcome())

        if (caseCalculationType == 1):
            for stockEntryTotalities in stockEntryTotalitiesList:
                markationStockRangeComposite = self.dynamicTimeMarkationManager.calculateLooseMarkationList(
                    stockEntryTotalities)
                observanceObjectResults = scenarioManager.calculateMarkationResults(
                    markationStockRangeComposite)
                observanceObjectResultsComposite.append(
                    observanceObjectResults)

            for observanceObjectResultsList in observanceObjectResultsComposite:
                for observanceObject in observanceObjectResultsList:
                    print(observanceObject.getScenarioOutcome())

        if (caseCalculationType == 2):
            currentTestIndex = 0
            for stockEntryTotalities in stockEntryTotalitiesList:
                if (currentTestIndex == 0):
                    print("Internal Index: " + str(currentTestIndex))
                    fullRangeStockList = self.dynamicTimeMarkationManager.calculateFullRangeList(
                        stockEntryTotalities)
                    # print("first index: "+str(fullRangeStockList[0]))
                    # print("last index: "+ str(fullRangeStockList[(len(fullRangeStockList)-1)]))

                    chronDict = scenarioManager.stockChronologicalLocationIdentifier(
                        fullRangeStockList)
                    stockRangeContainerTenMinuteSetComposite = self.dynamicTimeMarkationManager.calculateFullRangeMarkationList(
                        fullRangeStockList, chronDict, self.timeManager)
                    for tenMinuteSet in stockRangeContainerTenMinuteSetComposite:
                        print(tenMinuteSet[0]["symbol"])
                    currentTestIndex += 1

                observanceObjectResults = scenarioManager.calculateFullRangeMarkationResults(
                    stockRangeContainerTenMinuteSetComposite)
                observanceObjectResultsComposite.append(
                    observanceObjectResults)
                # print(observanceObjectResultsComposite)
            # for observanceObjectResults in observanceObjectResultsComposite[0]:
            # print(observanceObjectResults.getScenarioOutcome())

            self.dynamaTransit.transferObservanceObjectResults(
                observanceObjectResultsComposite)

    def setListGoldenGeese(self, listGoldenGeese):
        self.listGoldenGeese = listGoldenGeese

    def getListGoldenGeese(self):
        return self.listGoldenGeese
Ejemplo n.º 4
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.t = PerpetualTimer(0.03, self.sw16send)
Ejemplo n.º 5
0
class WS16Thread(threading.Thread):
    t = False
    ws16 = socket.socket()
    sendlast = time.time()
    mas = []

    def __init__(self):
        threading.Thread.__init__(self)
        self.t = PerpetualTimer(0.03, self.sw16send)

    def run(self):
        self.ws16.connect(('192.168.0.254', 8080))
        self.send(-1, True)
        while True:
            data = self.ws16.recv(1024)
            #print(data)
            if (data[1] == 12):
                sendlast = True
                data = data.split(b"\xcc\x0c").pop()
                print(data)
                i = 1
                for number in data[0:16]:
                    if (number == 2):
                        structure.set_value(i, False)
                    else:
                        structure.set_value(i, True)
                    if (structure.get_button(i) >= 0):
                        GLib.idle_add(
                            builder.get_object(
                                "i" +
                                str(structure.get_button(i))).set_from_file,
                            "button" + str(int(structure.get_value(i))) +
                            ".png")
                    i = i + 1
            time.sleep(0.01)

    def send(self, pin, val):
        if (pin > -1):
            if (val == 9):
                self.mas.append([pin, not structure.get_value(pin)])
            else:
                self.mas.append([pin, val])
        else:
            self.mas.append([pin, val])
        self.t.start()

    def sw16send(self):
        pin, val = self.mas.pop(0)
        if (pin == -1):
            self.ws16.send(
                b"\xaa\x1e\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xbb"
            )
        else:
            if (structure.get_value(pin) != bool(val)):
                if (bool(val) == True):
                    self.ws16.send(
                        b"\xaa\x0f" + structure.get_ws16(pin) +
                        b"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xbb"
                    )
                else:
                    self.ws16.send(
                        b"\xaa\x0f" + structure.get_ws16(pin) +
                        b"\x02\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xbb"
                    )
        if (len(self.mas) == 0):
            self.t.cancel()
        sql.addlog("INSERT INTO `SW16` (`pin`,`val`) VALUES (" + str(pin) +
                   "," + str(val) + ")")
Ejemplo n.º 6
0
sql.addlog("INSERT INTO `sys` (`text`) VALUES ( 'start')")
GPIO = GPIO()
GPIO.start()

signal.signal(signal.SIGINT, signal.SIG_DFL)
builder = Gtk.Builder()
builder.add_from_file('0.glade')
builder.connect_signals(connectsignals())

window = builder.get_object('window')
window.fullscreen()
screen = Gdk.Screen.get_default()
css_provider = Gtk.CssProvider()
css_provider.load_from_path('1.css')
context = Gtk.StyleContext()
context.add_provider_for_screen(screen, css_provider,
                                Gtk.STYLE_PROVIDER_PRIORITY_USER)
window.show_all()
vlcInstance = vlc.Instance(
    ['--logfile=/dev/null', '--quiet', '--no-video-on-top'])
builder.get_object("video").hide()
builder.get_object("МенюСвета").hide()

WS16Thread = WS16Thread()
WS16Thread.start()
DHT = DHT()
DHT.start()
timer = PerpetualTimer(0.1, OnTimer)
timer.start()
Gtk.main()
Ejemplo n.º 7
0
class AbatractNPLCompiler():
    def __init__(self, interval, paraengine_sdk_folder, paraengine_git_folder,
                 app_bits, callback):
        pass
        self.interval = interval
        self.paraengine_sdk_folder = paraengine_sdk_folder
        self.paraengine_git_folder = paraengine_git_folder
        self.app_bits = app_bits
        self.callback = callback
        self.pkg_txt_file_path = self.paraengine_sdk_folder + "/pkg_file.txt"
        self.zip_file_path = self.paraengine_sdk_folder + "/installer/main_full_mobile.zip"
        self.pkg_file_path = "%s/installer/main_full_mobile.pkg" % self.paraengine_sdk_folder
        self.pkg_txt_timer = PerpetualTimer(interval, self.CheckPkgTxtFile)
        self.pkg_timer = PerpetualTimer(interval, self.CheckPkgFile)

    def GetAppFullPath(self):
        pass

    def OpenApp(self, args):
        pass

    def CloseApp(self):
        pass

    def Clean(self):
        pass

    def MakeZip(self):
        pass

    def MakePkg(self):
        pass

    def RenamePkg(self):
        #self.CloseApp()
        filepath = "%s/installer/main_full_%sbits.pkg" % (
            self.paraengine_sdk_folder, self.app_bits)
        print "rename %s to %s" % (self.pkg_file_path, filepath)
        os.rename(self.pkg_file_path, filepath)
        if (self.callback):
            self.callback()

    def CheckPkgFile(self):
        if (os.path.exists(self.pkg_file_path)):
            self.pkg_timer.cancel()
            print "found %s" % self.pkg_file_path
            timer = Timer(5, self.RenamePkg)
            timer.start()
        else:
            print "waiting for %s %sbits" % (self.pkg_file_path, self.app_bits)

    def CheckPkgTxtFile(self):
        if (os.path.exists(self.pkg_txt_file_path)):
            self.pkg_txt_timer.cancel()
            print "found %s" % self.pkg_txt_file_path
            self.MakeZip()
        else:
            print "waiting for %s %sbits" % (self.pkg_txt_file_path,
                                             self.app_bits)

    def Start(self):
        pass