import os
import platform
import unittest

from nose.plugins.attrib import attr
from parameterized import parameterized

from conans.client.tools.files import replace_in_file
from conans.model.ref import PackageReference
from conans.paths import CONANFILE
from conans.test.utils.tools import TestClient
from conans.test.utils.visual_project_files import get_vs_project_files
from conans.test.utils.deprecation import catch_deprecation_warning

class MSBuildTest(unittest.TestCase):

    @attr('slow')
    @unittest.skipUnless(platform.system() == "Windows", "Requires MSBuild")
    def build_vs_project_test(self):
        conan_build_vs = """
from conans import ConanFile, MSBuild

class HelloConan(ConanFile):
    name = "Hello"
    version = "1.2.1"
    exports = "*"
    settings = "os", "build_type", "arch", "compiler", "cppstd"

    def build(self):
        msbuild = MSBuild(self)
        msbuild.build("MyProject.sln", verbosity="normal")

    def package(self):
        self.copy(pattern="*.exe")
"""
        client = TestClient()

        # Test cpp standard stuff

        files = get_vs_project_files(std="cpp17_2015")
        files[CONANFILE] = conan_build_vs

        client.save(files)
        with catch_deprecation_warning(self):
            client.run('create . Hello/1.2.1@lasote/stable -s cppstd=11 -s '
                       'compiler="Visual Studio" -s compiler.version=14', assert_error=True)
        with catch_deprecation_warning(self):
            client.run('create . Hello/1.2.1@lasote/stable -s cppstd=17 '
                       '-s compiler="Visual Studio" -s compiler.version=14')
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)

        files = get_vs_project_files()
        files[CONANFILE] = conan_build_vs

        # Try to not update the project
        client.cache._config = None  # Invalidate cached config

        replace_in_file(client.cache.conan_conf_path, "[general]",
                        "[general]\nskip_vs_projects_upgrade = True", output=client.out)
        client.save(files, clean_first=True)
        client.run("create . Hello/1.2.1@lasote/stable --build")
        self.assertNotIn("devenv", client.user_io.out)
        self.assertIn("Skipped sln project upgrade", client.out)

        # Try with x86_64
        client.save(files)
        client.run("export . lasote/stable")
        client.run("install Hello/1.2.1@lasote/stable --build -s arch=x86_64")
        self.assertIn("Release|x64", client.user_io.out)
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)

        # Try with x86
        client.save(files, clean_first=True)
        client.run("export . lasote/stable")
        client.run("install Hello/1.2.1@lasote/stable --build -s arch=x86")
        self.assertIn("Release|x86", client.user_io.out)
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)

        # Try with x86 debug
        client.save(files, clean_first=True)
        client.run("export . lasote/stable")
        client.run("install Hello/1.2.1@lasote/stable --build -s arch=x86 -s build_type=Debug")
        self.assertIn("Debug|x86", client.user_io.out)
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)

        # Try with a custom property file name
        files[CONANFILE] = conan_build_vs.replace(
                'msbuild.build("MyProject.sln", verbosity="normal")',
                'msbuild.build("MyProject.sln", verbosity="normal", property_file_name="mp.props")')
        client.save(files, clean_first=True)
        client.run("create . Hello/1.2.1@lasote/stable --build -s arch=x86 -s build_type=Debug")
        self.assertIn("Debug|x86", client.user_io.out)
        self.assertIn("Packaged 1 '.exe' file: MyProject.exe", client.out)
        full_ref = "Hello/1.2.1@lasote/stable:b786e9ece960c3a76378ca4d5b0d0e922f4cedc1"
        pref = PackageReference.loads(full_ref)
        build_folder = client.cache.package_layout(pref.ref).build(pref)
        self.assertTrue(os.path.exists(os.path.join(build_folder, "mp.props")))

    @unittest.skipUnless(platform.system() == "Windows", "Requires MSBuild")
    def reuse_msbuild_object_test(self):
        # https://github.com/conan-io/conan/issues/2865
        conan_build_vs = """
from conans import ConanFile, MSBuild

class HelloConan(ConanFile):
    name = "Hello"
    version = "1.2.1"
    exports = "*"
    settings = "os", "build_type", "arch", "compiler", "cppstd"

    def configure(self):
        del self.settings.compiler.runtime
        del self.settings.build_type

    def build(self):
        msbuild = MSBuild(self)
        msbuild.build("MyProject.sln", build_type="Release")
        msbuild.build("MyProject.sln", build_type="Debug")
        self.output.info("build() completed")
"""
        client = TestClient()
        files = get_vs_project_files()
        files[CONANFILE] = conan_build_vs

        client.save(files)
        client.run("create . danimtb/testing")
        self.assertIn("build() completed", client.out)

    @parameterized.expand([("True",), ("'my_log.binlog'",)])
    @unittest.skipUnless(platform.system() == "Windows", "Requires MSBuild")
    def binary_log_build_test(self, value):
        conan_build_vs = """
from conans import ConanFile, MSBuild

class HelloConan(ConanFile):
    name = "Hello"
    version = "1.2.1"
    exports = "*"
    settings = "os", "build_type", "arch", "compiler"

    def build(self):
        msbuild = MSBuild(self)
        msbuild.build("MyProject.sln", output_binary_log=%s)
"""
        client = TestClient()
        files = get_vs_project_files()
        files[CONANFILE] = conan_build_vs % value
        client.save(files)
        client.run("install . -s compiler=\"Visual Studio\" -s compiler.version=15")
        client.run("build .")

        if value == "'my_log.binlog'":
            log_name = value[1:1]
            flag = "/bl:%s" % log_name
        else:
            log_name = "msbuild.binlog"
            flag = "/bl"

        self.assertIn(flag, client.out)
        log_path = os.path.join(client.current_folder, log_name)
        self.assertTrue(os.path.exists(log_path))


import csv

def main():
    import argparse

    p = argparse.ArgumentParser()
    p.add_argument('list1', type=open)
    p.add_argument('list2', type=open)
    args = p.parse_args()

    fo = open('dataset.csv', 'w')
    w = csv.writer(fo)

    for x1, x2 in zip(args.list1, args.list2):
        x1, x2 = x1.strip(), x2.strip()
        w.writerow([x1, x2])

    fo.close()

if __name__ == '__main__':
    main()


#!/opt/local/bin/python

from lxml import etree
import re
import os
from bs4 import BeautifulSoup
import urllib3
import certifi
from multiprocessing import Process

def namespace(element):
    m = re.match('\{.*\}', element.tag)
    return m.group(0) if m else ''

def getComplexity(fname):
    r = etree.parse(fname).getroot()
    ns = namespace(r)
    #return r.xpath("count(//sisuTekst)")
    return len(r.findall('.//{0}sisuTekst'.format(ns)))

r = re.compile("(\d+)\.(\d+)\.(\d+)\-(.*)\.xml", re.I)
d = dict()
for filename in os.listdir('.'):
    print(filename)
    m = re.match(r, filename)
    if m:
        k = m.group(2) + "-" + m.group(3)
        if not k in d:
            d[k] = dict()

        d[k][m.group(4)] = getComplexity(filename)

for k, v in d.items():
    f = open('a-' + k + ".txt", "w")
    for a, c in d[k].items():
        f.write("%s %s\n" % (a, c))
    f.close()


import os
import random
import itertools
import sys
import pprint
import datetime
import numpy as np
import tensorflow as tf

from tensorflow.keras.optimizers import Adam

from collections import deque
from models.standard_agent import StandardAgent

from utils import conditional_decorator

class VPGSolver(StandardAgent):
    """
    A standard vpg_solver, inpired by:
      https://github.com/jachiam/rl-intro/blob/master/pg_cartpole.py
    NOTE:
        will need to examine steps (total_t), not episodes, as VPG doesn't
        implement episodes per-training-step
    """
    can_graph = True  # batch size is variable, cannot use tf graphing

    def __init__(self,
        experiment_name,
        env_wrapper,
        gamma=0.99,
        epsilon=None,
        epsilon_decay_rate=0.995,
        epsilon_min=0.1,
        batch_size=64,
        n_cycles=128,
        learning_rate=0.01,
        model_name="vpg",
        saving=True):

        super(VPGSolver, self).__init__(
            env_wrapper,
            model_name,
            experiment_name,
            saving=saving)

        self.label = "Batch"  # not by episode, by arbitrary batch
        self.action_size_tensor = tf.constant(self.action_size)

        self.gamma = gamma
        self.epsilon = epsilon
        self.epsilon_decay_rate = epsilon_decay_rate
        self.epsilon_min = epsilon_min

        # TODO could go to standard..
        self.batch_size = batch_size
        self.n_cycles = n_cycles

        self.memory = []  # state
        self.solved_on = None

        self.model = self.build_model()
        self.optimizer = Adam(lr=learning_rate)  # decay=learning_rate_decay)

        self.load_state()

        # TODO rollout steps

    @staticmethod
    def discount_future_cumsum(episode_rewards, gamma):
        """
        Takes:
            A list of rewards per step for an episode
        Returns:
            The future reward at each step, with the future discounting
            rate applied from that step onwards.
        """
        ep_rwds = np.array(episode_rewards)
        n = len(ep_rwds)
        discounts = gamma ** np.arange(n)
        discounted_futures = np.zeros_like(ep_rwds, dtype=np.float64)
        for j in range(n):
            discounted_futures[j] = sum(ep_rwds[j:] * discounts[:(n-j)])

        assert len(discounted_futures) == len(episode_rewards)
        return discounted_futures

    def solve(self, max_iters, verbose=False, render=False):
        start_time = datetime.datetime.now()
        env = self.env_wrapper.env
        state, done, episode_rewards = env.reset(), False, []
        success_steps = 0

        for batch_num in range(max_iters):
            # Refresh every batch (on-policy)
            state_batch, act_batch, batch_future_rewards = [], [], []

            for step in range(self.n_cycles):
                if render:
                    env.render()

                action = self.act(self.model, state, epsilon=self.epsilon)
                state_next, reward, done, _ = env.step(action)

                # Custom reward if required by env wrapper
                reward = self.env_wrapper.reward_on_step(
                    state, state_next, reward, done, step)

                state_batch.append(state.copy())
                act_batch.append(np.int32(action))
                episode_rewards.append(reward)

                # NOTE: Removed copy
                state = state_next

                self.report_step(step, batch_num, max_iters)

                if done:

                    # At the end of each episode:
                    # Create a list of future rewards,
                    #  discounting by how far in the future
                    batch_future_rewards += list(
                        self.discount_future_cumsum(
                            episode_rewards, self.gamma))
                    self.scores.append(success_steps)
                    state, done, episode_rewards = env.reset(), False, []
                    success_steps = 0
                else:
                    success_steps += 1

            # Add any trailing rewards to done
            batch_future_rewards += list(
                self.discount_future_cumsum(
                    episode_rewards, self.gamma)
            )
            episode_rewards = []

            # HANDLE END OF EPISODE
            batch_advs = np.array(batch_future_rewards)

            # This is R(tau), normalised
            normalised_batch_advs = (
                (batch_advs - np.mean(batch_advs))
                / (np.std(batch_advs) + 1e-8)
            )

            self.remember(state_batch, act_batch, normalised_batch_advs)
            self.learn(*self.get_batch_to_train())

            solved = self.handle_episode_end(
                state, state_next, reward,
                step, max_iters, verbose=verbose)

            if solved:
                break

        self.elapsed_time += (datetime.datetime.now() - start_time)
        return solved

    def remember(self, state_batch, act_batch, batch_advs):

        self.memory = (state_batch, act_batch, batch_advs)

    def get_batch_to_train(self):

        assert len(self.memory[0]) == len(self.memory[1]), f"{len(self.memory[0])}, {len(self.memory[1])}"
        assert len(self.memory[1]) == len(self.memory[2]), f"{len(self.memory[1])}, {len(self.memory[2])}"

        minibatch_i = np.random.choice(len(self.memory[0]),
            min(self.batch_size, len(self.memory[0])),
            )

        sampled_memory = []
        for i in range(len(self.memory)):
            sampled_memory.append(tf.convert_to_tensor([self.memory[i][j] for j in minibatch_i]))

        self.memory = []  # Only learning from last set of trajectories

        return sampled_memory

    def learn(self, sts, acts, advs):
        """Updated the agent's decision network based
        on a sample of previous decisions it has seen.
        Here, we combine the target and action networks.
        """

        loss_value = self.take_training_step(sts, acts, advs)

        if self.epsilon:
            if self.epsilon > self.epsilon_min:
                self.epsilon *= self.epsilon_decay_rate

        return loss_value

    @conditional_decorator(tf.function, can_graph)
    def take_training_step(self, sts, acts, advs):
        tf.debugging.assert_equal(tf.shape(sts)[0], tf.size(acts), summarize=1)
        tf.debugging.assert_equal(tf.size(acts), tf.size(advs), summarize=1)

        with tf.GradientTape() as tape:

            # One step away from Pi_theta(at|st)
            pi_action_logits = self.model(sts)

            action_one_hots = tf.one_hot(
                acts, self.action_size_tensor, dtype=tf.float64)

            # This IS pi_theta(at|st), only at the actual action taken
            pi_action_log_probs = tf.math.reduce_sum(
                action_one_hots * tf.nn.log_softmax(pi_action_logits),
                axis=1)

            tf.debugging.assert_equal(tf.size(advs), tf.size(pi_action_log_probs))

            loss_value = - tf.math.reduce_mean(
                advs * pi_action_log_probs
            )

        grads = tape.gradient(loss_value, self.model.trainable_variables)

        self.optimizer.apply_gradients(
            zip(grads, self.model.trainable_variables))

        return loss_value

    def save_state(self, add_to_save={}):
        """Save a (trained) model with its weights to a specified file.
        Metadata should be passed to keep information avaialble.
        """

        self.save_state_to_dict(append_dict={
            "optimizer_config": self.optimizer.get_config(),
            "epislon": self.epsilon,
        })

        self.model.save(self.model_location)

    def load_state(self):
        """Load a model with the specified name"""

        model_dict = self.load_state_from_dict()

        print("Loading weights from", self.model_location + "...", end="")

        if os.path.exists(self.model_location):
            self.model = tf.keras.models.load_model(self.model_location)

            self.optimizer = self.optimizer.from_config(self.optimizer_config)
            del model_dict["optimizer_config"], self.optimizer_config

            print(" Loaded.")

        else:
            print(" Model not yet saved at loaction.")

        if "memory" in model_dict:
            del model_dict["memory"]

        print("Loaded state:")
        pprint.pprint(model_dict, depth=1)


import discord
import config
import requests
import asyncio

client = discord.Client()

async def change_status():
    await client.wait_until_ready()
    while client.is_ready():
        await client.change_presence(activity=discord.Game(name=f"!mop | {len(client.guilds)} guilds", type=1))
        await asyncio.sleep(20)

@client.event
async def on_ready():
    print('MoppenBot op account: {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.lower().startswith('!mop'):
        args = message.content.split(" ")
        params = {"likes": "true"}
        if len(args) > 1:
            if args[1] == "nsfw":
                params["nsfw"] = "true"
                r = requests.get("https://moppenbot.nl/api/random/", params=params)
            else:
                params["q"] = args
                r = requests.get("https://moppenbot.nl/api/search/", params=params)
        else:
            r = requests.get("https://moppenbot.nl/api/random/", params=params)
        if r.status_code == 200:
            data = r.json()
            if data["success"]:
                embed = discord.Embed(title="Mop " + str(data["joke"]["id"]), description=data["joke"]["joke"], color=0xffff00)
                embed.set_footer(text="Van " + str(data["joke"]["author"]) + " | " + str(data["joke"]["likes"]) + " 👍")
                msg = await message.channel.send(embed=embed)
                await msg.add_reaction("👍")
                return
        embed = discord.Embed(title="Error", description="Er is een error opgetreden. Meld dit.")
        await message.channel.send(embed=embed)

    if message.content.lower().startswith('!help'):
        args = message.content.split(" ")
        if len(args) > 1:
            if args[1] == "api":
                embed=discord.Embed(title="Moppenbot Api Informatie", description="Help Commando van de Moppenbot")
                embed.add_field(name="Main endpoint: /api/random/", value="Krijg een random mop", inline=False)
                embed.add_field(name="Mogelijke Param: nsfw=true", value="Krijg een mop die NSFW kan zijn", inline=True)
                embed.add_field(name="Mogelijke Param: likes=true ", value="Krijg ook hoeveel likes de bot heeft", inline=True)
                embed.add_field(name="Zoek endpoint: /api/search/", value="Zoek een mop met param q=<zoekwoord>", inline=True)
                embed.set_footer(text="Door: Jens de Router 💻 Jederu #5961")
                await message.channel.send(embed=embed)
        else:
            embed=discord.Embed(title="Moppenbot Help", description="Help Commando van de Moppenbot")
            embed.add_field(name="!mop", value="Krijg een random mop", inline=False)
            embed.add_field(name="!mop nsfw", value="Krijg een mop die NSFW kan zijn", inline=True)
            embed.add_field(name="!mop <zoekwoord>", value="Zoek een mop op zoekwoord", inline=True)
            embed.set_footer(text="Door: Jens de Router 💻 Jederu #5961")
            await message.channel.send(embed=embed)

@client.event
async def on_reaction_add(reaction, user):
    if not user.bot:
        if reaction.emoji == "👍":
            params = {
                "api_key": config.API_KEY,
                "user": user.id,
                "joke": int(reaction.message.embeds[0].title.replace("Mop ", "")),
            }
            requests.get("https://moppenbot.nl/api/like/", params=params)

client.loop.create_task(change_status())
#client.run(config.TOKEN)


from flask import Flask, render_template, jsonify, redirect
from flask_pymongo import PyMongo
import pymongo
import scrape_mars
import config

import os
#cwd = os.getcwd()
#app = Flask(__name__, template_folder=cwd)

app = Flask(__name__)

conn = 'mongodb+srv://gghali:' + config.pwd + '@cluster0-6epwg.mongodb.net/test'
client = pymongo.MongoClient(conn)
mars_db=client.marsScrape_DB
collection = mars_db.marsData

@app.route("/")
def index():
    marsScrape_Data = mars_db.marsData.find_one()
    return render_template("index.html", marsData=marsScrape_Data)

@app.route("/scrape")
def scrape():
    mars_data = scrape_mars.scrape()
    marsD = mars_db.marsData
    marsD.update(
        {},
        mars_data,
        upsert=True
    )

    return redirect("http://localhost:5000/", code=302)

if __name__ == "__main__":
    app.run(debug=True)

# code to connect without Atlas


import pygame
from random import *
import time

#fonction qui definit les positions x et y de l'objet pomme
def apple(window_x,window_y,block_size,snakeLst):
        global x_apple, y_apple
        x_apple=randint(0, window_x-block_size)
        y_apple=randint(0, window_y-block_size)
        for XnY in snakeLst:
            if (x_apple,y_apple)==XnY:
                apple(window_x,window_y,block_size)
        return x_apple, y_apple

#affiche le message lorsque l'on meurt/perd apres avoir pris un m ur on apres s'être mangé soit meme
def end_message(gameDisplay,fontColor,color):
    msg="You lost, q to quit or r to restart, e for main menu"
    font = pygame.font.Font("images/Misc/font.ttf", 50)
    text = font.render(msg, 1, color)
    textpos = text.get_rect()
    textpos.centerx = gameDisplay.get_rect().centerx
    textpos.centery = gameDisplay.get_rect().centery-50
    gameDisplay.fill(fontColor)
    gameDisplay.blit(text, textpos)
    gameDisplay.blit(gameDisplay, (0, 0))
    pygame.display.flip()

#fonction qui affiche ce que l'on voit lorsque l'on clique sur crédits dans le Menu Principal
def credits_jeu(gameDisplay, black, white):
    msg="Everything excepting music was created by"
    font = pygame.font.Font("images/Misc/font.ttf", 40)
    text = font.render(msg, 1, black)
    textpos = text.get_rect()
    textpos.centerx = gameDisplay.get_rect().centerx
    textpos.centery = gameDisplay.get_rect().centery-50
    msg2="Quentin Tourette"
    text2 = font.render(msg2, 1, black)
    textpos2 = text2.get_rect()
    textpos2.centerx = gameDisplay.get_rect().centerx
    textpos2.centery = gameDisplay.get_rect().centery
    msg3="Music Main menu : Arcade Game Menu Music Loop (8Bit Style)"
    text3 = font.render(msg3, 1, black)
    textpos3 = text3.get_rect()
    textpos3.centerx = gameDisplay.get_rect().centerx
    textpos3.centery = gameDisplay.get_rect().centery+50
    msg4="Music In Game : Vexare - The Clockmaker"
    text4 = font.render(msg4, 1, black)
    textpos4 = text4.get_rect()
    textpos4.centerx = gameDisplay.get_rect().centerx
    textpos4.centery = gameDisplay.get_rect().centery+100
    gameDisplay.fill(white)
    gameDisplay.blit(text, textpos)
    gameDisplay.blit(text2, textpos2)
    gameDisplay.blit(text3, textpos3)
    gameDisplay.blit(text4, textpos4)
    gameDisplay.blit(gameDisplay, (0, 0))
    pygame.display.flip()
    while True:
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
                quit()
            elif event.type==pygame.KEYDOWN:
                debut_jeu()

#boucle du jeu principal
def jeu(music):
    #init des couleurs
    white = (255,255,255)
    black = (0,0,0)
    red = (200,0,0)
    green = (0,200,0)
    blue = (0,0,200)

    #init pygame + font pour tout ce qui est texte
    pygame.init()
    pygame.font.init()

    #init des variables
    gameExit=False
    test="bonjour cette partie du code vient d'etre activé"
    window_x=1280
    window_y=720
    block_size=17
    x=window_x/2-block_size
    y=window_y/2-block_size
    x_change=0
    y_change=0
    score=1
    direction=0
    vertical=1
    horizontal=1
    global x_apple,y_apple
    x_apple=randint(0, window_x-block_size)
    y_apple=randint(0, window_y-block_size)

    #init de l'horloge de jeu
    clock=pygame.time.Clock()

    gameDisplay = pygame.display.set_mode((window_x,window_y))
    pygame.display.set_caption("SNAKE v3.02")
    pygame.display.update()
    gameExit=False

    background_img = pygame.image.load("images/Backgrounds/Background.png")

    Head_img = pygame.image.load("images/Snake/Head.png")
    Body_img = pygame.image.load("images/Snake/Body.png")
    apple_img = pygame.image.load("images/Misc/apple.png")

    Head_img = pygame.transform.scale(Head_img, (block_size ,block_size))
    Body_img = pygame.transform.scale(Body_img, (block_size ,block_size))

    Music_Menu = pygame.mixer.music.load("music/IG.ogg")
    apple_sound = pygame.mixer.Sound("music/apple_sound.ogg")

    if music:
        pygame.mixer.music.play(-1)

    #boucle principale du jeu qui tourne 30*/sec
    while True:
        #creation des listes contenant x y et direction du serpent en dehors de la boucle de jeu pour qu'elle ne soit pas réinit a chaque fois
        snakeDir=[]
        snakeLst=[]

        #positionnement de l'objet
        gameDisplay.blit(background_img,(0,0))

        #boucle de jeu qui tourne tant que l'on ne perd pas
        while not gameExit:
            #si le serpent et en dehors des dimensions de la fenetre, fait sortir de la boucle principale après 0.5 secondes
            if x<=0 or x+block_size>window_x or y<=0 or y+block_size>window_y:
                gameExit=True
                time.sleep(0.5)

            #test de la touche sur laquelle l'utilisateur appuie ou s'il appuie sur la croix
            for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type==pygame.KEYDOWN:
                    if event.key==pygame.K_ESCAPE:
                        pygame.quit()
                        quit()

                    if vertical==1:
                        if event.key==pygame.K_UP:
                            y_change=-block_size
                            x_change=0
                            vertical=0
                            horizontal=1
                            direction=1

                        elif event.key==pygame.K_DOWN:
                            y_change=block_size
                            x_change=0
                            vertical=0
                            horizontal=1
                            direction=3

                    if horizontal==1:
                        if event.key==pygame.K_LEFT:
                            x_change=-block_size
                            y_change=0
                            vertical=1
                            horizontal=0
                            direction=4

                        elif event.key==pygame.K_RIGHT:
                            x_change=block_size
                            y_change=0
                            vertical=1
                            horizontal=0
                            direction=2

            #creation d'une liste qui renvoi les position x et ySound( de la tete actuelle afin de les stocker
            snakeHeadPOS = []
            snakeHeadPOS.append(x)
            snakeHeadPOS.append(y)

            snakeLst.append(snakeHeadPOS)
            if len(snakeLst)>score:
                    del snakeLst[0]

            #ajout de la direction que chaque morceaux du corps doit prendre (droite,gauche,haut,bas)
            snakeDir.append(direction)
            if len(snakeDir)>score:
                del snakeDir[0]
            snakeDIR=list(reversed(snakeDir))

            #redéfinition des variables x et y, permettant de faire bouger le serpent
            x+=x_change
            y+=y_change

            #test si on se mange soi meme
            for i in range(len(snakeLst)):
                try:
                    if snakeLst[0]==snakeLst[i+1]:
                        gameExit=True
                        time.sleep(0.5)
                except:
                    pass

            #remplissage par le fond d'écran pour "redessiner" nos objets dessus
            gameDisplay.blit(background_img, (0, 0), (0, 0, window_x, window_y))

            #création des lists contenant les x et y contenants chaque parties du corps

            snakeHead = snakeHeadPOS

            snakeBody = []

            if len(snakeBody)>score+1:
                del snakeBody[0]

            #rotation de la tete et de la queue
            Head_DIR = snakeDIR[0]
            Head_img = pygame.transform.rotate(Head_img, (Head_DIR-1)*90)

            #on positionne l'objet corps
            A=0
            for XnY in snakeLst:
                x_Body=int(XnY[0])
                y_Body=int(XnY[1])
                if A==0:
                    pass
                elif A==len(snakeLst):
                    pass
                else:
                    gameDisplay.blit(Body_img,[x_Body,y_Body])
                A+=1

            #on positionne l'objet corps
            gameDisplay.blit(Body_img,snakeLst[0])

            #on positionne l'objet tete
            gameDisplay.blit(Head_img,[x,y])
            #pygame.draw.rect(gameDisplay, couleur, [x1,y1,block_size,block_size])

            #test si la pomme est mangé, si oui on redefinit de nouvelles coordonnées
            if (x>=x_apple and x<=x_apple+block_size and y>=y_apple and y<=y_apple+block_size) or (x+block_size>=x_apple and x+block_size<=x_apple+block_size and y+block_size>=y_apple and y+block_size<=y_apple+block_size):
                score+=1
                if music:
                    pygame.mixer.Sound.play(apple_sound)
                apple(window_x,window_y,block_size,snakeLst)

            #création l'objet pomme
            apple_img = pygame.transform.scale(apple_img, (block_size+2 ,block_size+2))
            gameDisplay.blit(apple_img,[x_apple,y_apple])

            #création l'objet score
            score_message = "Score : " + str(score-1)
            font = pygame.font.Font("images/Misc/font.ttf", 60)
            score_text = font.render(score_message, 1, black)
            gameDisplay.blit(score_text, [0,0])

            #affichage de tout les objets créé jusque la + définition de la répétition de la boucle soit 30X/sec
            pygame.display.update()

            #remise droite de l'image de la tete pour ne pas qu'elle tourne en continu
            Head_img = pygame.transform.rotate(Head_img, -(Head_DIR-1)*90)

            #définition du nombre d'images par seconde (ici 30)
            clock.tick(30)

        #boucle qui se lance après qu'on ai perdu, test les touches pour savoir si l'utilisateur veut recommencer ou quitter
        while gameExit:
            end_message(gameDisplay, white, red)
            for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    pygame.quit()
                    quit()
                if event.type==pygame.KEYDOWN:
                    if event.key==pygame.K_a:
                        pygame.quit()
                        quit()
                    elif event.key==pygame.K_r:
                        if music:
                            pygame.mixer.fadeout(1000)
                        jeu(music)
                    elif event.key==pygame.K_e:
                        debut_jeu()

#fonction qui définit la fenetre, affiche tout le menu principal et test si l'utilisateur appuie sur l'un des "bouttons"
def debut_jeu():
    white = (255,255,255)
    black = (0,0,0)
    red = (200,0,0)
    green = (0,200,0)
    blue = (0,0,200)

    pygame.init()
    pygame.font.init()

    test="bonjour cette partie du code vient d'etre activé"

    window_x=1280
    window_y=720

    music=True

    gameDisplay = pygame.display.set_mode((window_x,window_y))
    pygame.display.set_caption("SNAKE v3.02")
    gameExit=False

    Music_Menu = pygame.mixer.music.load("music/Main Menu.ogg")
    pygame.mixer.music.play(-1)

    startup = pygame.image.load("images/Backgrounds/Startup.png")

    music_button = pygame.image.load("images/Misc/music_button.png")
    button_off = pygame.image.load("images/Misc/button_off.png")

    music_button = pygame.transform.scale(music_button, (50 ,50))
    button_off = pygame.transform.scale(button_off, (50 ,50))

    gameDisplay.blit(startup,[0,0])
    gameDisplay.blit(music_button,[window_x-80,window_y-80])
    pygame.display.update()

    def music_display():
        gameDisplay.blit(startup,[0,0])
        if music:
            gameDisplay.blit(music_button,[window_x-80,window_y-80])
            pygame.display.update()
        if not music:
            gameDisplay.blit(music_button,[window_x-80,window_y-80])
            gameDisplay.blit(button_off,[window_x-80,window_y-80])
            pygame.display.update()

    #test si l'utilisateur appuie sur la croix ou s'il clic sur l'un des bouttons et lance la commande appropriée
    while True:
        if not music:
            pygame.mixer.music.pause()

        if music:
            pygame.mixer.music.unpause()

        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                pygame.quit()
                quit()
            elif event.type==pygame.MOUSEBUTTONUP:
                a = list(pygame.mouse.get_pos())
                x=a[0]
                y=a[1]
                if x>=500 and x<=790 and y >=435 and y<=500:
                    pygame.mixer.quit()
                    jeu(music)
                elif x>=515 and x<=780 and y>=530 and y<=600:
                    pygame.quit()
                    quit()
                elif x>=460 and x<=840 and y>=635 and y<=705:
                    credits_jeu(gameDisplay,black,white)
                elif x>=window_x-80 and x<=window_x-30 and y>=window_y-90 and y<=window_y-40 and music==True:
                    music=False
                elif x>=window_x-80 and x<=window_x-30 and y>=window_y-90 and y<=window_y-40 and music==False:
                    music=True

            elif event.type==pygame.KEYDOWN:
                if event.key==pygame.K_ESCAPE:
                    pygame.quit()
                    quit()

            music_display()

#lance la fonction qui lance le menu principal soit tout le jeu
#début du jeu
debut_jeu()


from flask import Flask, request, render_template, redirect, jsonify
from PIL import Image, ImageFilter
import numpy as np
from mnist import Classifier
import tensorflow as tf
import sys

def Get_predicted_index():
	image = Image.open("./written.png")
	imaeg = image.thumbnail((28, 28))
	image.save("thumbnailed.png")
	image = image.convert('L')
	image = 1.0 - np.asarray(image, dtype="float32") / 255
	image = image.reshape((1,784))
	'''
	image = Image.open("./1.png")
	imaeg = image.thumbnail((28, 28))
	image.save("thumbnailed.png")
	image = image.convert('L')
	image = 1.0 - np.asarray(image, dtype="float32") / 255
	image = image.reshape((1,784))
	image = Image.open(f)
	'''
	'''
	newimage = Image.open("./thumbnailed.png")
	newimage = 1.0 - np.asarray(newimage, dtype="float32") / 255
	#print(newimage)
	newimage = newimage.reshape((1,784))
	'''
	classifier = Classifier()
	prediction = classifier.predict(image)

	print(prediction)
	temp = (prediction[0], prediction[1], prediction[2], prediction[3],
		prediction[4], prediction[5], prediction[6], prediction[7], prediction[8], prediction[9])
	print(temp)
	predicrted_index = max(enumerate(temp), key=lambda x: x[1])[0]
	print(predicrted_index)
	return predicrted_index

Get_predicted_index()
#print(jsonify({ str(k): float(v * 100) for k,v in prediction.items() }))


#!/usr/bin/env python

from __future__ import print_function
import boto3
import sys

route53 = boto3.client('route53')

paginate_hosted_zones = route53.get_paginator('list_hosted_zones')
paginate_resource_record_sets = route53.get_paginator('list_resource_record_sets')

domains = [domain.lower().rstrip('.') for domain in sys.argv[1:]]

for zone_page in paginate_hosted_zones.paginate():
    for zone in zone_page['HostedZones']:
        if domains and not zone['Name'].lower().rstrip('.') in domains:
            continue

        for record_page in paginate_resource_record_sets.paginate(HostedZoneId = zone['Id']):
            for record in record_page['ResourceRecordSets']:
                if record.get('ResourceRecords'):
                    for target in record['ResourceRecords']:
                        print(record['Name'], record['TTL'], 'IN', record['Type'], target['Value'], sep = "\t")
                elif record.get('AliasTarget'):
                    print(record['Name'], 300, 'IN', record['Type'], record['AliasTarget']['DNSName'], '; ALIAS', sep = "\t")
                else:
                    raise Exception('Unknown record type: {}'.format(record))


from pathlib import Path
import os
import subprocess

from os import listdir
from os.path import isfile, join

def checkSubmission(requiredFiles):
    allOk = True
    missingFiles = []
    for r in requiredFiles:
        if not Path(r).is_file():
            allOk = False
            missingFiles.append(r)
            print('ERROR:required file {} not found! '.format(r) )
    return allOk, missingFiles

def createZippedFile(dirName):
    subprocess.call(['rm', dirName + '.zip'])
    os.system('zip -r ' + dirName + '.zip ' + 'Readme.txt ' + 'src/*.cc ' + 'src/*.h ' + 'src/CMakeLists.txt')
    print('done')

if __name__ == '__main__':
    print('checking for required files..')
    requiredFiles = ['Readme.txt', 'src/CMakeLists.txt', 'src/store.cc', 'src/threadpool.h']
    allOk, missingFiles = checkSubmission(requiredFiles)
    if not allOk:
        print('Aborting. Please make sure all required files are present')
    else:
        firstname = input('Enter first name: ')
        lastname = input('Enter last name: ')
        dirName = firstname + '_' + lastname + '_p3'
        createZippedFile(dirName)


#!/usr/bin/python

import json
import sys
from lxml import etree
from copy import deepcopy
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("src", help='&source of the json file&')
parser.add_argument("dst", help='&destination of new xml file&')
parser.add_argument("-vr", help='&version, productID&', default="mxb")
args = parser.parse_args()
if(not (args.src.endswith('.json')) and (args.dst.endswith('.xml'))):
    sys.exit()

provisioning = etree.Element("provisioning",
                             version="1.1", productID=str(args.vr))
nvm = etree.SubElement(provisioning, 'nvm')

with open(str(args.src)) as f:
    data = json.load(f)
    for i in data:
        etree.SubElement(nvm, "param",
                         name=str(i), value=str(data[i]))

content = etree.tostring(provisioning).decode('ascii')
content = content.replace("><", "> \n<")
root = etree.XML(content)
output = etree.tostring(root, xml_declaration=True,
                        encoding='UTF-8').decode('ascii')
p = open(str(args.dst), "w")
p.write(str(output))
p.close()
print("Json to XMl extracted!")


from config import mysql
from sqlalchemy import create_engine
import pandas as pd
import matplotlib.pyplot as plt

engine = create_engine(mysql['host'] + mysql['user'] + mysql['password'] + mysql['database'])
connection = engine.connect()
salaries = pd.read_sql("SELECT * FROM salaries", connection)
titles = pd.read_sql("SELECT * FROM titles", connection)

plt.style.use('ggplot')
plt.hist(salaries.salary, bins=20)
plt.title('Common Salary Ranges for Employees')
plt.xlabel('Salaries')
plt.ylabel('Number')
plt.tight_layout()
plt.savefig('images/histogram.png', dpi=200)

plt.style.use('seaborn')
merged = pd.merge(titles, salaries, on='emp_no', how='left')
means = merged.groupby('title').mean()
means.plot(kind='barh', y=['salary'])
plt.legend().set_visible(False)
plt.xlabel('Average Salary')
plt.ylabel('Title')
plt.tight_layout()
plt.savefig('images/bar-chart.png', dpi=200)

print(salaries[salaries.emp_no == 499942])
print(titles[titles.emp_no == 499942])


#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import cv2
import sys
import numpy as np

import openface.helper

#얼국 인식용 xml 파일
face_classifier = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

#전체 사진에서 얼굴 부위만 잘라 리턴
def face_extractor(img):
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    #얼굴 찾기
    faces = face_classifier.detectMultiScale(gray,1.3,5)
    #찾은 얼굴이 없으면 None으로 리턴
    if faces is():
        return None
    for(x,y,w,h) in faces:
        cropped_face = img[y:y+h, x:x+w]
    return cropped_face

if __name__ == "__main__" :

    folder_name = sys.argv[1]
    trainCnt = int(sys.argv[2])

    # 추출한 얼굴 사진 저장할 폴더 정하기
    outputDir = '../training-images/'+folder_name+'/'
    openface.helper.mkdirP(outputDir)

    #카메라 실행
    cap = cv2.VideoCapture(0)
    #저장할 이미지 카운트 변수
    count = 0
    while True:
        ret, frame = cap.read()
        #얼굴 감지 하여 얼굴만 가져오기
        if face_extractor(frame) is not None:
            count+=1
            face_tmp = cv2.resize(face_extractor(frame),(200,200))
            face = cv2.cvtColor(face_tmp, cv2.COLOR_BGR2GRAY)
            #faces폴더에 jpg파일로 저장
            # ex > faces/user0.jpg   faces/user1.jpg ....
            file_name_path = outputDir+str(count)+'.jpg'
            cv2.imwrite(file_name_path,face)

            # cv.putText(img, '글자', location, font, fontScale, color, thickness)
            cv2.putText(face,str(count),(50,50),cv2.FONT_HERSHEY_COMPLEX,1.2,(255,0,0),2)
            #
            cv2.imshow('Face Cropper',face)
        else:
            print("Face not Found")
            pass

        if cv2.waitKey(1)==13 or count==trainCnt:
            break

    cap.release()
    cv2.destroyAllWindows()
    print('Colleting Samples Complete!!!')


import numpy as np
import torch
import torch.nn as nn
from torch.autograd import Variable
import gym
import matplotlib.pyplot as plt

class Net(nn.Module):
    def __init__(self, input_size, n_l1, num_classes):
        super(Net, self).__init__()
        self.fc1 = nn.Linear(input_size, n_l1)
        self.fc1.weight.data.normal_(0, 0.3)
        self.fc1.bias.data.zero_()
        self.fc1.bias.data += 0.1
        self.tanh = nn.Tanh()
        self.fc2 = nn.Linear(n_l1, num_classes)
        self.fc2.weight.data.normal_(0, 0.3)
        self.fc2.bias.data.zero_()
        self.fc2.bias.data += 0.1

    def forward(self, x):
        out = self.fc1(x)
        out = self.tanh(out)
        out = self.fc2(out)
        return out

class PG:
    def __init__(self, n_features, n_actions, learning_rate, gamma):
        self.net = Net(n_features, 10, n_actions)
        self.optimizer = torch.optim.Adam(self.net.parameters(), lr=learning_rate)
        self.criterion = nn.CrossEntropyLoss(reduce=False)

        self.gamma = gamma

        self.n_actions = n_actions

        self.ep_obs, self.ep_as, self.ep_rs = [], [], []

    def store_transition(self, s, a, r):
        self.ep_obs.append(s)
        self.ep_as.append(a)
        self.ep_rs.append(r)

    def choose_action(self,observation):
        observation = Variable(torch.FloatTensor(observation)).view(1,-1)
        prob_weights = self.net.forward(observation)

        softmax = nn.Softmax(dim=1)
        prob_weights = softmax(prob_weights)
        prob_weights.squeeze_()

        action = np.random.choice(range(prob_weights.shape[0]), p=prob_weights.data.numpy())

        return action

    def learn(self):
        # 1. get reward
        discounted_ep_rs_norm = Variable(torch.FloatTensor(self._discount_and_norm_rewards()))

        # 2. calculate loss
        ep_obs_var = Variable(torch.FloatTensor(self.ep_obs))
        all_act_prob = self.net.forward(ep_obs_var)

        ep_as_var = Variable(torch.LongTensor(np.array(self.ep_as)))

        loss = self.criterion(all_act_prob, ep_as_var)
        loss = torch.mean(loss * discounted_ep_rs_norm)

        # 3. back propogation
        self.optimizer.zero_grad()
        loss.backward()
        self.optimizer.step()

        # 4. clear memory
        self.ep_obs, self.ep_as, self.ep_rs = [], [], []

    def _discount_and_norm_rewards(self):
        # discount episode rewards
        discounted_ep_rs = np.zeros_like(self.ep_rs)
        running_add = 0
        for t in reversed(range(0, len(self.ep_rs))):
            running_add = running_add * self.gamma + self.ep_rs[t]
            discounted_ep_rs[t] = running_add

        # normalize episode rewards
        discounted_ep_rs -= np.mean(discounted_ep_rs)
        discounted_ep_rs /= np.std(discounted_ep_rs)
        return discounted_ep_rs

env = gym.make('MountainCar-v0')
env = env.unwrapped

pg = PG(n_features = env.observation_space.shape[0], n_actions = env.action_space.n, learning_rate = 0.02, gamma = 0.995)

for episode in range(1000):
    observation = env.reset()
    while True:
        if episode == 999:
            env.render()
        action = pg.choose_action(observation)

        observation_, reward, done, info = env.step(action)
        pg.store_transition(observation, action, reward)

        observation = observation_

        if done:
            # calculate running reward
            ep_rs_sum = sum(pg.ep_rs)
            if 'running_reward' not in globals():
                running_reward = ep_rs_sum
            else:
                running_reward = running_reward * 0.99 + ep_rs_sum * 0.01

            print("episode:", episode, "  reward:", int(running_reward))

            pg.learn()
            break


from django.shortcuts import render, redirect, get_object_or_404
from django.views import View
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import ListView
from .models import City
from .forms import CityInitForm
from django.contrib import messages

# create city with model form
class CreateCity(LoginRequiredMixin, View):

    TEMPLATE_NAME = "city/create.html"

    # init form
    def get(self, request, *args, **kwargs):

        form = CityInitForm()

        parseData = {
            'title': 'Create City',
            'form': form
        }

        return render(request, self.TEMPLATE_NAME, parseData)

    # pass form data to database and redirect
    def post(self, request, *args, **kwargs):

        form = CityInitForm(request.POST, request.FILES)

        # if form is valid
        if form.is_valid():

            # save db
            form.save()

            # flash messages
            messages.success(request, " {} City Added ".format(
                request.POST.get("englishName")))

            return redirect("city:home")

        parseData = {
            'title': 'Create City',
            'form': form
        }

        return render(request, self.TEMPLATE_NAME, parseData)

# update city data through model form
class UpdateCity(LoginRequiredMixin, View):

    TEMPLATE_NAME = "city/edit.html"

    # get relevent object details
    # bound model form
    def get(self, request, *args, **kwargs):

        city = get_object_or_404(City, pk=kwargs.get('pk'))
        form = CityInitForm(instance=city)

        parseData = {
            'title': 'Update {}'.format(city.englishName),
            'form': form
        }

        return render(request, self.TEMPLATE_NAME, parseData)

    def post(self, request, *args, **kwargs):

        city = get_object_or_404(City, pk=kwargs.get('pk'))
        form = CityInitForm(request.POST, instance=city)

        parseData = {
            'form': form,
            'title': 'Update {}'.format(city.englishName)
        }

        if form.is_valid():
            # save record
            form.save()

            messages.success(request, " {} City Added ".format(
                request.POST.get("englishName")))

            return redirect("city:home")

        else:
            return render(request, self.TEMPLATE_NAME, parseData)

class RemoveCity(LoginRequiredMixin, View):

    def get(self, request, *args, **kwargs):

        city = get_object_or_404(City, pk=kwargs.get('pk'))
        response = city.delete()

        city_name = city.englishName

        # success
        if response[0] == 1:
            messages.success(
                request, " {} City Removed".format(city_name)
            )

        else:
            messages.success(
                request,
                "{} can't remove now, please try again later".format(city_name)
            )

        return redirect("city:home")

class ListCity(LoginRequiredMixin, ListView):

    paginate_by = 10
    template_name = "city/list.html"

    def get_context_data(self, *args, **kwargs):
        contextData = super().get_context_data(*args, **kwargs)
        contextData['title'] = 'City'
        return contextData

    def get_queryset(self):

        searchSinhalaName = self.request.GET.get('name')

        if searchSinhalaName:

            queryset = City.objects.filter(
                englishName__icontains=searchSinhalaName.strip()
            )
            queryset = queryset.values(
                'pk',
                'sinhalaName',
                'englishName',
                'district__englishName')
            queryset = queryset.order_by('pk')

        else:

            queryset = City.objects.all()
            queryset = queryset.select_related('district')
            queryset = queryset.values(
                'pk',
                'sinhalaName',
                'englishName',
                'district__englishName')
            queryset = queryset.order_by('pk')

        return queryset


from typing import Callable, Optional, Sequence

from pytorch_lightning import LightningDataModule
from torch_geometric.data import DataLoader, Dataset, RandomNodeSampler

from src.datamodules.datasets.hyperspectral_dataset import HyperSpectralCustomDataset

class HyperSpectralDataModule(LightningDataModule):
    """
        Base DataModule which converts spectral datasets to graphs.
        Conversion happens on first run only.

        --------Example--------

        from datamodules.hyperspectral_datamodule import HyperSpectralDataModule

        dm = HyperSpectralDataModule(
            url='http://www.ehu.eus/ccwintco/uploads/e/ee/PaviaU.mat',
            gt_url='http://www.ehu.eus/ccwintco/uploads/5/50/PaviaU_gt.mat',
            data_dir='data/pavia_university',
            mat_key='paviaU',
            gt_mat_key='paviaU_gt',
        )
        dm.prepare_data()
        dm.setup()

        for batch in dm.train_dataloader():
            x, y, edge_index, batch, train_mask, val_mask, test_mask = batch.x, batch.y, batch.edge_index, \
            batch.batch, batch.train_mask, batch.val_mask, batch.test_mask

        -----------------------
    """

    def __init__(
            self,
            url: str,
            gt_url: str,
            data_dir: str = "data/",
            num_neighbours: int = 10,
            mat_key: str = "",
            gt_mat_key: str = "",
            batch_size: int = 1,
            train_val_split: Sequence[int] = (30, 15),
            num_workers: int = 0,
            pin_memory: bool = False,
            transform: Optional[Callable] = None,
            pre_transform: Optional[Callable] = None,
    ):
        """
        Args:
            url:                    URL to matlab data file
            gt_url:                 URL to matlab ground truth data file
            data_dir:               Path do data folder
            num_neighbours:         Number of nearest neighbours connected with node
            mat_key:                Matlab dict key where data is stored
            gt_mat_key:             Matlab ground truth key where data is stored
            batch_size:             Batch size (1 - hyperspectral datasets consist of one graph)
            train_val_split:        Number of nodes for training, validation per class (remaining for test)
            num_workers:            Number of processes for data loading.
            pin_memory:             Whether to pin CUDA memory (slight speed up for GPU users)
        """
        super().__init__()
        self.url = url
        self.gt_url = gt_url
        self.data_dir = data_dir
        self.mat_key = mat_key
        self.gt_mat_key = gt_mat_key
        self.num_neighbours = num_neighbours
        self.transform = transform
        self.pre_transform = pre_transform
        self.batch_size = batch_size
        self.train_val_split = train_val_split
        self.num_workers = num_workers
        self.pin_memory = pin_memory

        self.data_train: Optional[Dataset] = None
        self.data_val: Optional[Dataset] = None
        self.data_test: Optional[Dataset] = None

    def prepare_data(self):
        """Download data if needed. This method is called only from a single GPU.
        Do not use it to assign state (self.x = y)."""
        HyperSpectralCustomDataset(
            self.data_dir,
            url=self.url,
            gt_url=self.gt_url,
            mat_key=self.mat_key,
            train_val_split=self.train_val_split,
            gt_mat_key=self.gt_mat_key,
            num_neighbours=self.num_neighbours,
            transform=self.transform,
            pre_transform=self.pre_transform,
        )

    def setup(self, stage: Optional[str] = None):
        """Load data. Set variables: self.data_train, self.data_val, self.data_test."""
        dataset = HyperSpectralCustomDataset(
            self.data_dir,
            url=self.url,
            gt_url=self.gt_url,
            mat_key=self.mat_key,
            train_val_split=self.train_val_split,
            gt_mat_key=self.gt_mat_key,
            num_neighbours=self.num_neighbours,
            transform=self.transform,
            pre_transform=self.pre_transform,
        )

        self.data_train = dataset
        self.data_val = dataset
        self.data_test = dataset

    def train_dataloader(self):
        return RandomNodeSampler(
            self.data_train.data,
            num_parts=6,
            num_workers=self.num_workers,
            shuffle=True
        )

    def val_dataloader(self):
        return DataLoader(
            dataset=self.data_val,
            batch_size=self.batch_size,
            num_workers=self.num_workers,
            pin_memory=self.pin_memory,
            shuffle=False,
        )

    def test_dataloader(self):
        return DataLoader(
            dataset=self.data_test,
            batch_size=self.batch_size,
            num_workers=self.num_workers,
            pin_memory=self.pin_memory,
            shuffle=False,
        )