Ejemplo n.º 1
0
 def __init__(self):
     Game.screen_width = database.Database.screen_width
     Game.screen_height = database.Database.screen_height
     Game.highscore = database.Database.highscore
     self.score = 0
     self.run = True
     self.pause = False
     self.game_over = False
     self.frame_counter = 0
     self.abilities_recharge = 0
     self.difficulty_spawn = database.Database.spawn_rate_on_start
     self.window = None
     self.background = None
     self.bullets = []
     self.knights = []
     self.copters = []
     self.bombs = []
     self.player = hero.Hero()
     #############
     self.window = pygame.display.set_mode(
         (Game.screen_width, Game.screen_height))
     #        self.cop_ai = copterai.AI()
     pygame.display.set_caption("Game by Meleron")
     images.Images()
     self.launch_game()
Ejemplo n.º 2
0
def save_logs(conn, cacheid, logstr, user_token):
    """ Save logs to the database """

    cacheid = cacheid.upper()
    json_object = json.loads(logstr)
    page_info = json_object['pageInfo']
    size = page_info['size']
    total_rows = page_info['totalRows']
    pages = math.ceil(total_rows / size)
    if pages > 5:
        pages = 5
    json_array = json_object['data']

    for i in range(1, pages + 1):
        if i > 1:
            json_array = get_more_logs(i, size, user_token)
            if json_array is None:
                return

        for log in json_array:
            l_b = logbook.LogBook()
            l_b.cacheid = cacheid
            l_b.logid = log['LogID']
            l_b.accountid = log['AccountID']
            l_b.logtype = log['LogType']
            l_b.logimage = log['LogTypeImage']
            l_b.logtext = htmlcode.cache_images(log['LogText'], SESSION)
            l_b.created = clean_up(log['Created'])
            l_b.visited = clean_up(log['Visited'])

            save_log(conn, l_b)

            user = users.Users()
            user.accountid = log['AccountID']
            user.username = log['UserName']
            user.accountguid = log['AccountGuid']
            user.avatarimage = log['AvatarImage']
            user.findcount = log['GeocacheFindCount']
            user.hidecount = log['GeocacheHideCount']

            save_user(conn, user)

            for img in log['Images']:
                image = images.Images()
                image.cacheid = cacheid
                image.accountid = log['AccountID']
                image.imageid = img['ImageID']
                image.logid = log['LogID']
                image.filename = img['FileName']
                image.created = clean_up(img['Created'])
                image.name = img['Name']
                image.descr = img['Descr']

                save_image(conn, image)
Ejemplo n.º 3
0
 def __init__():
     Game.window = pygame.display.set_mode((Game.screen_width, Game.screen_height))
     pygame.display.set_caption("Game by Meleron")
     #Game.left_sprites = images.Images.load_images_set("pics\Left_Armature_RUN_", 16)
     #Game.right_sprites = images.Images.load_images_set("pics\Right_Armature_RUN_", 16)
     #Game.background = images.Images.load_image("pics\Flat Nature Art.png")
     images.Images()
     Game.left_sprites = images.Images.left_sprites
     Game.right_sprites = images.Images.right_sprites
     Game.background = images.Images.background
     Game.launch_game()
Ejemplo n.º 4
0
    def next_frame(self, net, style_data, subject_data, layer):
        im = images.Images()

        sigma = self.__get_sigma(self.iteration)
        step_size = self.__get_step_size(self.iteration)

        self.__take_steps(net, sigma, step_size, style_data, subject_data, layer)

        self.iteration += 1

        return im.visualize_src(net)
Ejemplo n.º 5
0
def get_image(conn, imageid):
    """ return image array from db """

    cursor = conn.cursor()
    cursor.execute("SELECT * from cacheimages where imageid = ?", (imageid, ))
    ret = cursor.fetchone()
    cursor.close()

    if ret is not None and ret[0] != "":
        image = images.Images()
        image.cacheid = ret[0]
        image.accountid = ret[1]
        image.imageid = ret[2]
        image.logid = ret[3]
        image.filename = ret[4]
        image.created = ret[5]
        image.name = ret[6]
        image.descr = ret[7]
        row = image

    else:
        row = None

    return row
Ejemplo n.º 6
0
import images as im

#generate csv from filesystem
#i used ../data/data_laika_loading.py

# open database connction
image_table = im.Images()

#get all images
#images = image_table.get_all()

#get all with a substring
# something like this sql = "SELECT * FROM IMAGES where TAGS LIKE '%" + tag + "%'"
images = image_table.get_all_by_tag("test")

for name, row in images.iterrows():
    print(row['filename'], row['tags'])

Ejemplo n.º 7
0
from dataclasses import asdict
import logging

from flask import Flask, send_file, render_template, request
from flask_restful import Api, Resource
from werkzeug.exceptions import NotFound

import images as img

logging.basicConfig(level=logging.DEBUG)

app = Flask(__name__)
api = Api(app)
images = img.Images("dane", "opisane")


@app.route("/")
def main_page():
    return render_template("main_page.html")


@app.route("/image")
def get_image():
    id = request.args.get("id")
    try:
        file_object = images.get_image(id).asPng()
    except img.ImageNotExistsError as e:
        raise NotFound(str(e)) from e

    return send_file(file_object, mimetype="image/PNG")
Ejemplo n.º 8
0
def _downloadData(classNames, imagesPerClass):
    images = imgs.Images(IMAGES_DIR, 64, 64, imagesPerClass)
    for className in classNames:
        if not _doesImagesExists(className, imagesPerClass):
            images.downloadImages(className)
Ejemplo n.º 9
0
import images as im
import random
import csv

#generate csv from filesystem
#i used ../data/data_missing_link_groundtruth_loading.py
IMAGE_CSV = '../data/data/MissingLink_Groundtruth_PNG.csv'

# open database connction
image_table = im.Images(db_location="127.0.0.1", db_port=63333)


# blow away entire db and rebuild from ../data/data/Laika-Kubo.csv
def refresh_images():
    # drop teh images table
    image_table.drop_table()
    # create a images table from scratch
    image_table.create_table()

    # fill the images table from csv
    image_table.fill_table(path=IMAGE_CSV)
    #

    # save your work
    image_table.commit()


def add_tag(file, tag):
    image = None
    if isinstance(file, (int)):
        image = image_table.get_by_index(file)
Ejemplo n.º 10
0
def main():
    env = images.Images(os.getcwd())
    maxEpisode = 5000
    replayBuffer = deque()

    with tf.Session() as sess:
        mainDQN = DQN.DQN(sess)
        tf.global_variables_initializer().run()
        saver = tf.train.Saver()

        for episode in range(maxEpisode):
            e = 1. / ((episode / 10) + 1)
            done = False
            stepCounter = 0
            env.restart()
            state = env.initState()
            print("episode : %d" % episode)

            while not done:
                if np.random.rand(1) < e:
                    action = random.randrange(10, 170)
                    print("Episode : %d random degree : %d" %
                          (episode, action))
                else:
                    action = mainDQN.predict(state)[0]
                    action = np.argmax(action) + 10
                    print("Episode : %d predict degree : %d" %
                          (episode, action))
                    # action.index(max(action)) + 10

                nextState, reward, done = env.action(action)
                if done:
                    reward = -100

                replayBuffer.append((state, action, reward, nextState, done))
                print("next State length : %d" % len(nextState))

                # URL = "http://192.168.190.130:8000/"
                URL = "http://35.200.208.151/"
                current_state = ",".join(map(str, state[:42]))
                next_state = ",".join(map(str, nextState[:42]))
                round = nextState[42]
                ball_position = nextState[43]
                ball_number = nextState[44]

                print(
                    "------------------------------------------------------------"
                )
                print("current_state : %s" % type(current_state))
                print("next_state : %s" % type(next_state))
                print("round : %s" % type(round))
                print("ball_position : %s" % type(ball_position))
                print("action : %s" % type(action))
                print("done : %s" % type(done))

                requests.post(URL,
                              data=json.dumps({
                                  "current_state": current_state,
                                  "next_state": next_state,
                                  "round": int(round),
                                  "ball_position": ball_position,
                                  "ball_number": int(ball_number),
                                  "action": int(action),
                                  "done": done
                              }))

                if len(replayBuffer) > REPLAY_MEMORY:
                    replayBuffer.popleft()

                state = nextState
                stepCounter += 1

            print("Episode : {} steps : {}".format(episode, stepCounter))

            if episode % 10 == 2:
                for _ in range(50):
                    miniBatch = random.sample(replayBuffer, 10)
                    loss, _ = simpleReplayTrain(mainDQN, miniBatch)
                print("Loss :", loss)
                saver.save(sess, "./save/DQN/model")