Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

añado ejercicio WebSocket #102

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 28 additions & 30 deletions Miguel/Ejercicio_Chartist/js/javascript.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
//Ejercicio gráfica de humedad y temperatura de madrid usando Chartist.
//Variable donde se guardaran los datos de las etiquetas y las barras de la gráfica.
var data = {
labels: [],
series: [ [],[],[] ]
};
//Función para obtener datos y pintar la gráfica.
function llamada(url){
fetch(url)
.then(res => res.json())
.then(dat => {
console.log(dat);
let lista = dat.list;
for(i = 0; i < lista.length; i++){
if(lista[i].dt_txt.slice(11) == "15:00:00"){
data.series[1].push(lista[i].main.temp_max);
data.series[2].push(lista[i].main.humidity);
data.labels.push(lista[i].dt_txt.slice(0,10));
}else if(lista[i].dt_txt.slice(11) == "03:00:00"){
data.series[0].push(lista[i].main.temp_min);
}
}
var chart = new Chartist.Bar('.ct-chart', data, options, responsiveOptions);
//Función para animar la grafica *MINIFICADA*
var seq=0,delays=50,durations=500;chart.on("created",function(){seq=0}),chart.on("draw",function(e){if(seq++,"bar"===e.type)e.element.animate({opacity:{begin:seq*delays+1e3,dur:durations,from:0,to:1}});else if("label"===e.type&&"x"===e.axis)e.element.animate({y:{begin:seq*delays,dur:durations,from:e.y+100,to:e.y,easing:"easeOutQuart"}});else if("label"===e.type&&"y"===e.axis)e.element.animate({x:{begin:seq*delays,dur:durations,from:e.x-100,to:e.x,easing:"easeOutQuart"}});else if("point"===e.type)e.element.animate({x1:{begin:seq*delays,dur:durations,from:e.x-10,to:e.x,easing:"easeOutQuart"},x2:{begin:seq*delays,dur:durations,from:e.x-10,to:e.x,easing:"easeOutQuart"},opacity:{begin:seq*delays,dur:durations,from:0,to:1,easing:"easeOutQuart"}});else if("grid"===e.type){var a={begin:seq*delays,dur:durations,from:e[e.axis.units.pos+"1"]-30,to:e[e.axis.units.pos+"1"],easing:"easeOutQuart"},s={begin:seq*delays,dur:durations,from:e[e.axis.units.pos+"2"]-100,to:e[e.axis.units.pos+"2"],easing:"easeOutQuart"},t={};t[e.axis.units.pos+"1"]=a,t[e.axis.units.pos+"2"]=s,t.opacity={begin:seq*delays,dur:durations,from:0,to:1,easing:"easeOutQuart"},e.element.animate(t)}});
})
.catch(err => console.log(`Error: ${err}`));
}
//Opciones de la grafica *MINIFICADAS*
var options={seriesBarDistance:30},responsiveOptions=[["screen and (min-width: 641px) and (max-width: 1024px)",{seriesBarDistance:10,axisX:{labelInterpolationFnc:function(n){return n}}}],["screen and (max-width: 640px)",{seriesBarDistance:5,axisX:{labelInterpolationFnc:function(n){return n[0]}}}]];
//Llamada a la
llamada("http://airemad.com/api/v1/weather/S002");
(function getData() {
//Opciones de la grafica *MINIFICADAS*
var options={seriesBarDistance:30},responsiveOptions=[["screen and (min-width: 641px) and (max-width: 1024px)",{seriesBarDistance:10,axisX:{labelInterpolationFnc:function(n){return n}}}],["screen and (max-width: 640px)",{seriesBarDistance:5,axisX:{labelInterpolationFnc:function(n){return n[0]}}}]];
//Variable donde se guardaran los datos de las etiquetas y las barras de la gráfica.
var data = {
labels: [],
series: [ [],[],[] ]
}

fetch("http://airemad.com/api/v1/weather/S002")
.then(res => res.json())
.then(dat => {
let lista = dat.list;
for(i = 0; i < lista.length; i++){
if(lista[i].dt_txt.slice(11) == "15:00:00"){
data.series[1].push(lista[i].main.temp_max);
data.series[2].push(lista[i].main.humidity);
data.labels.push(lista[i].dt_txt.slice(0,10));
}else if(lista[i].dt_txt.slice(11) == "03:00:00"){
data.series[0].push(lista[i].main.temp_min);
}
}
var chart = new Chartist.Bar('.ct-chart', data, options, responsiveOptions);
//Función para animar la grafica *MINIFICADA*
var seq=0,delays=50,durations=500;chart.on("created",function(){seq=0}),chart.on("draw",function(e){if(seq++,"bar"===e.type)e.element.animate({opacity:{begin:seq*delays+1e3,dur:durations,from:0,to:1}});else if("label"===e.type&&"x"===e.axis)e.element.animate({y:{begin:seq*delays,dur:durations,from:e.y+100,to:e.y,easing:"easeOutQuart"}});else if("label"===e.type&&"y"===e.axis)e.element.animate({x:{begin:seq*delays,dur:durations,from:e.x-100,to:e.x,easing:"easeOutQuart"}});else if("point"===e.type)e.element.animate({x1:{begin:seq*delays,dur:durations,from:e.x-10,to:e.x,easing:"easeOutQuart"},x2:{begin:seq*delays,dur:durations,from:e.x-10,to:e.x,easing:"easeOutQuart"},opacity:{begin:seq*delays,dur:durations,from:0,to:1,easing:"easeOutQuart"}});else if("grid"===e.type){var a={begin:seq*delays,dur:durations,from:e[e.axis.units.pos+"1"]-30,to:e[e.axis.units.pos+"1"],easing:"easeOutQuart"},s={begin:seq*delays,dur:durations,from:e[e.axis.units.pos+"2"]-100,to:e[e.axis.units.pos+"2"],easing:"easeOutQuart"},t={};t[e.axis.units.pos+"1"]=a,t[e.axis.units.pos+"2"]=s,t.opacity={begin:seq*delays,dur:durations,from:0,to:1,easing:"easeOutQuart"},e.element.animate(t)}});
})
.catch(err => console.log(`Error: ${err}`));
})()
7 changes: 1 addition & 6 deletions Miguel/Ejercicio_NASA/js/javascript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* @file exercise to get photos of the curiosity robot from Mars
* @author Miguel Martin-Maestro Lopez
Expand Down Expand Up @@ -38,7 +37,7 @@ function NasaRequest(soles,limit){
}
});
}else{
console.log("Límite de llamadas superado, intentelo de nuevo.")
reject("Límite de llamadas superado, intentelo de nuevo.")
};
});
};
Expand All @@ -49,7 +48,3 @@ async function init(){
document.getElementById("resultado").querySelector("img").src = currentValue.photos[0].img_src;
}
init();




22 changes: 13 additions & 9 deletions Miguel/Ejercicio_Router/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ function fetchAireMad(url,id){
};

//Crear una sub-lista dentro del último campo del menú con los valores de 'idList'
const stationsIdList = ["P001", "P002", "P003", "S001", "S002", "S004", "S006", "S008", "S011", "S012", "S016", "S017", "S018", "S019", "S024", "S025", "S027", "S028", "S030", "S035", "S036", "S038", "S039", "S040", "S047", "S048", "S049", "S050", "S054", "S055", "S056", "S057", "S058", "S059", "S060"];
function loadStations() {
const stationsIdList = ["P001", "P002", "P003", "S001", "S002", "S004", "S006", "S008", "S011", "S012", "S016", "S017", "S018", "S019", "S024", "S025", "S027", "S028", "S030", "S035", "S036", "S038", "S039", "S040", "S047", "S048", "S049", "S050", "S054", "S055", "S056", "S057", "S058", "S059", "S060"];

stationsIdList.forEach(function(element){
let li = document.createElement("li")
let a = document.createElement("a");
a.href = '/stations/:'+element;
a.textContent = element;
li.append(a);
document.querySelector(".desplegable ul").append(li);
})
stationsIdList.forEach(function(element){
let li = document.createElement("li")
let a = document.createElement("a");
a.href = '/stations/'+ element;
a.textContent = element;
li.append(a);
document.querySelector(".desplegable ul").append(li);
})
}

loadStations()
1 change: 1 addition & 0 deletions Miguel/Ejercicio_api_github/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ ehthumbs_vista.db

# Folder config file
[Dd]esktop.ini
desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/
Expand Down
134 changes: 74 additions & 60 deletions Miguel/Ejercicio_api_github/js/javascript.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,91 @@
/**
* @file exercise to get the data of a github user including his email from the events
* @author Miguel Martin-Maestro Lopez
* @version 1.1.0
* @version 1.2.0
*/


/**
* @description fetch to get user data from the api of github
* @param {string} url //url created in the listener below
* @param {string} url url created in the listener below
*/
function searchUser(url){
fetch(url)
.then(function(response){
return response.json();
})
.then(function(data){

document.getElementById("resultado").innerHTML = "";

var nombre = data.name;

var p = document.createElement("p");
p.setAttribute("id","informacionDeUsuario");
document.getElementById("resultado").append(p);
p.innerText = "Nombre y Apellidos: " + data.name + "\n" + "Nombre de usuario: " + data.login + "\n" + "Bio: " + data.bio + "\n" + "GitHub: " + data.html_url + "\n" + "Ciudad: " + data.location;
var img = document.createElement("img");
img.src = data.avatar_url;
p.insertAdjacentElement("afterend",img);

var urlEvent = url + "/events";

fetch(urlEvent)
.then(function(response){
return response.json();
})
.then(function(data){

var email;

for(i = 0; i < data.length; i++){

var commits = data[i].payload.commits;

if(commits){

for(j = 0; j < commits.length; j++){

if(commits[j].author.name == nombre){

email = commits[j].author.email;
fetch(url)
.then(function(response){
if(response.status === 404) {
document.getElementById("resultado").innerHTML = "404 - USUARIO NO ENCONTRADO"
} else if (response.status === 200) {
response.json()
.then(function(data){
pintarDatos(data, url)
})
}
})
.catch(function(error) {console.error('Error-Usuario no encontrado:', error)
})
}
/**
* @description function to paint users data
* @param {object} data data received from searchUser function
* @param {string} url url of the last fetch needed to build the next fetch to users/events
*/
function pintarDatos(data, url) {
document.getElementById("resultado").innerHTML = ""
var p = document.createElement("p")
p.setAttribute("id","informacionDeUsuario")
document.getElementById("resultado").append(p)
p.innerText = "Nombre y Apellidos: " + data.name + "\n" + "Nombre de usuario: " + data.login + "\n" + "Bio: " + data.bio + "\n" + "GitHub: " + data.html_url + "\n" + "Ciudad: " + data.location
var img = document.createElement("img")
img.src = data.avatar_url
p.insertAdjacentElement("afterend",img)

if (data.email != null) {
document.getElementById("informacionDeUsuario").innerText += "\n" + "Email: " + email
} else {
var urlEvent = url + "/events"
var name = data.name
buscarEmail (urlEvent, name)
}
}

if(email != ""){
document.getElementById("informacionDeUsuario").innerText += "\n" + "Email: " + email;
}
return;
}
}
}
}if(email == undefined){ document.getElementById("informacionDeUsuario").innerText += "\n" + "Email: No encontrado." ;}
})
})
.catch(function(error){console.error('Error:', error)
});
};
/**
* @description function to find the email
* @param {string} urlEvent the new url for fetch data about events
* @param {string} name name to verify authorship of the commits to find the correct email
*/
function buscarEmail(urlEvent, name) {
fetch(urlEvent)
.then(function(response) {
return response.json()
})
.then(function(data){
var email
for(i = 0; i < data.length; i++){
var commits = data[i].payload.commits

if(commits){
for(j = 0; j < commits.length; j++){
if(commits[j].author.name == name){
email = commits[j].author.email
if(email != ""){
document.getElementById("informacionDeUsuario").innerText += "\n" + "Email: " + email
}
return
}
}
}
}
if(email == undefined){ document.getElementById("informacionDeUsuario").innerText += "\n" + "Email: No encontrado." }
})
}

/**
* @description it takes as part of the parameter of searchUser(url) the value entered by the user in the input
* @event searchUser
* @fires btnUser#searchUser
*/
document.getElementById("btnUser").addEventListener("click", function(){
var usuario = document.getElementById("textBox").value;
searchUser("https://api.github.com/users/" + usuario);
});


var usuario = document.getElementById("textBox").value
searchUser("https://api.github.com/users/" + usuario)
})
Loading