Permalink
Browse files

Merge branch 'master' of https://github.com/j3nnn1/tools

  • Loading branch information...
Jenn
Jenn committed Feb 28, 2013
2 parents e9dd9be + 00a58b7 commit 0d7cc0a6a7eacf21375e9018adc63eb1993bd77d
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+origen=$1
+destino=$2
+
+if [ "x${1}" = "x" ]; then
+ echo 'Parametros incompletos: '
+ echo './convertTSVtoCSV fileIN.tsv fileCSV.csv'
+ exit
+fi
+
+if [ "x${2}" = "x" ]; then
+ echo 'Parametros incompletos: '
+ echo './convertTSVtoCSV fileIN.tsv fileCSV.csv'
+ exit
+fi
+
+tr "\t" "," < $origen > $destino
@@ -0,0 +1,12 @@
+
+file=$1
+if [ "x${1}" = "x" ]; then
+ echo 'Parametros faltantes, ./convert_y_n_to_numeric.sh file.csv'
+ exit
+fi
+
+sed 's/Y/1/g' $file > $file.tmp
+sed 's/N/0/g' $file.tmp > $file.outsed
+rm $file.tmp
+echo 'finish!'
+
@@ -0,0 +1,64 @@
+#!/usr/bin/perl -w
+use strict;
+use Data::Dumper;
+#use common::sense;
+use Scalar::Util qw {looks_like_number};
+
+
+my $table = 'creditos';
+my $fileout = 'CreateCreditos.sql';
+my $filetoupload = 'UBA_DMEF_2012_recu_03.csv';
+my $typestring = 'varchar(255)';
+my $typenumber = 'numeric';
+my @fields;
+my @fieldnames;
+my %fieldsbd;
+my $line;
+
+open(FILE, '<', $filetoupload) or die ("No puede leer el archivo \n");
+open(FILETWO, '>', $fileout);
+
+print FILETWO 'CREATE TABLE '. $table . ' ( ';
+
+
+while($line = <FILE>) {
+
+ if ($.==2) {
+ @fields = split(',', $line);
+ my $i = 0;
+ foreach (@fields){
+ chomp($_);
+ $_ =~ s/"//g;
+ if (looks_like_number($_)) {
+ $fieldnames[$i] =~ s/"//g;
+ chomp($fieldnames[$i]);
+ $fieldsbd{$fieldnames[$i]} = $typenumber;
+ }
+ else {
+ $fieldnames[$i] =~ s/"//g;
+ chomp($fieldnames[$i]);
+ $fieldsbd{$fieldnames[$i]} = $typestring;
+ }
+ $i++;
+ }
+ }
+ elsif($.>2) {
+ last;
+ }
+ else {
+ @fieldnames = split(',', $line);
+ }
+}
+
+#print Dumper %fieldsbd;
+foreach (@fieldnames) {
+ print FILETWO "$_ " . $fieldsbd{$_}.",";
+ print FILETWO "\n";
+}
+print FILETWO ');';
+close(FILE);
+close(FILETWO);
+
+
+
+
@@ -0,0 +1,10 @@
+
+
+file=$1
+if [ "x${1}" = "x" ]; then
+ echo "Falta nombre de archivo del SCRIPT SQL a ejecutar"
+ echo "./executeScriptSQL.sh ScripSQL.sql"
+ exit
+fi
+
+psql -d recuperatorio -f $file
@@ -0,0 +1,24 @@
+
+#sh getDataFromTableToCSV.sh cred /media/misperoles/git/tools/converCSVToCreateSQL/salida.out
+table=$1
+output=$2
+
+if [ "x${1}" = "x" ]; then
+ echo 'Parametros faltantes, ./getDataFromTableToCSV.sh nameTable fileout.csv'
+ exit
+fi
+
+if [ "x${2}" = "x" ]; then
+ echo 'Parametros faltantes, ./convert_y_n_to_numeric.sh nameTable fileout.csv'
+ exit
+fi
+
+
+echo ' COPY '$table" TO '"$output"' WITH CSV HEADER" > sql.tmp
+
+psql -d recuperatorio -f sql.tmp
+
+rm sql.tmp
+
+echo 'finish!'
+
View
@@ -1,70 +0,0 @@
-#!/usr/bin/R
-
-##dirout = './out'
-simbadO = read.table('simbad.csv', header=T, sep=';')
-hipparcosO = read.table('hipparcos.csv', header=T, sep=';')
-cruzados = read.table('id_cruzados.csv', header=T, sep=',')
-
-simbad = data.frame(ID=simbadO$identifier, RA_J2000=simbadO$RA_J2000, DE_J2000=simbadO$DE_J2000)
-hipparcos = data.frame(ID=hipparcosO$HIP, RA_J2000=hipparcosO$RA_J2000, DE_J2000=hipparcosO$DE_J2000)
-
-simbad = as.matrix(simbad)
-hipparcos = as.matrix(hipparcos)
-
-mdistances = dist(rbind(simbad[1:nrow(simbad),2:3], hipparcos[1:nrow(hipparcos), 2:3]))
-
-#diit to matrix
-mdist =as.matrix(mdistances)
-
-#matrix to vector
-vecdist <- c(mdist)
-
-#withoutzero
-vecdist <- vecdist[vecdist>0]
-
-#unclassify stars, do a hist
-hdatadist = hist(vecdist);
-
-#dist cruzados
-allcruzados = rbind(as.matrix(cruzados[2:nrow(cruzados),3:4]), as.matrix(cruzados[2:nrow(cruzados),5:6]))
-
-
-axis(1, max(allcruzados), paste("best",k.best,sep="\n"), col = "red", col.axis = "red")
-
-
-#classify stars, do a hist
-mdistcruz = dist(allcruzados)
-
-#matrix to vector.
-vecdistcruz = c(as.matrix(mdistcruz))
-
-#oh god why
-hdatacruz = hist(vecdistcruz, col="green", add=T)
-
-#where cut
-#hdatacruz$breaks
-
-#deleting with out zerc
-sincero = vecdistcruz[vecdistcruz>0]
-
-#min distance to be hyades de 0 a 2
-mincruz = min(sincero)
-
-#plotting
-h = hist(vecdist);
-plot(h$counts, log="xy", pch=20, col="blue",
- main="Log-normal distribution",
- xlab="Value", ylab="Frequency")
-
-hc = hist(sincero)
-points(hc$counts, pch=20, col="green",
- main="Log-normal distribution",
- xlab="Value", ylab="Frequency")
-
-#filtering distances
-
-
-
-
-
-
View
@@ -1,82 +0,0 @@
-
-simbadO = read.table('simbad.csv', header=T, sep=';')
-hipparcosO = read.table('HIPPARCOS.csv', header=T, sep=';')
-
-#cut columns
-a = as.matrix(cbind(simbadO$RA_J2000, simbadO$DE_J2000), nrow=nrow(simbadO), byrow=T)
-b = as.matrix(cbind(hipparcosO$RA_J2000, hipparcosO$DE_J2000), nrow=nrow(hipparcosO), byrow=T)
-
-#putting rownames
-rownames(a) <- simbadO$identifier
-rownames(b) <- hipparcosO$HIP
-
-min.dist <- array()
-min.dist.name <- array()
-dists.ab <- array()
-
-for (i in 1:nrow(a)){ #simbad
- for (j in 1:nrow(b)) { #hipparcos
- dists.ab[j] <- dist(rbind(a[i,],b[j,])) #almaceno las distancias
- }
- min.dist.name[i] <- which.min(dists.ab)
- min.dist[i] <- min(dists.ab)
-}
-
-nrow(dists.ab)
-length(dists.ab)
-length(min.dist)
-
-#this is the value to look
-head(min.dist)
-########################
-
-#getting the limit
-cruzados = read.table('id_cruzados.csv', header=T, sep=',')
-mcruzados = as.matrix(cruzados)
-
-for (i in 1:nrow(mcruzados)) {
-
- #create a mini matrix with one row.
- mnewmini = rbind(mcruzados[i,3:4], mcruzados[i,5:6])
-
- #matriz distance
- disti = dist(mnewmini)
-
- ##adding distance to dataframe.
- #format sci
- cruzados$distancia[i] = format(disti , sci = FALSE)
-
- #printdataframe
- cruzados$distancia[i]
-}
-maxjoindist=as.numeric(maxjoindist)
-maxjoindist = max(cruzados$distancia)
-
-#getting joins
-#min.dist.name
-maxjoindist=as.numeric(maxjoindist)
-#candidate = min.dist [ min.dist < maxjoindist]
-candidate.name = cbind(min.dist.name, min.dist < maxjoindist)
-rownames(candidate.name) = simbadO$Identifier
-
-#get index
-candidate.name = cbind(candidate.name, row(candidate.name))
-candidate.name <- candidate.name[,1:3]
-colnames(candidate.name) = c('ID_HIP','candidato', 'id_simbad')
-
-candidate.name.df = subset(candidate.name, candidate.name[,2]==1)
-candidate.name.df = data.frame(candidate.name.df)
-
-#creating df with merge with hipp and simbad
-hipparcosO = read.table('hipparcos.csv', header=T, sep=',')
-hipparcosO = hipparcosO[,1:8]
-
-#add to b the index row
-hipparcosO = cbind(hipparcosO, indexcandidate= 1:length(dists.ab))
-
-
-dfmergeall = merge(candidate.name.df, hipparcosO, by.x='ID_HIP', by.y='indexcandidate')
-
-#saving
-write.csv(dfmergeall, 'identificacioncruzadasimbadhipparcos.csv')
-write.csv(candidate.name, 'hipparcoshyades.csv')
Oops, something went wrong.

0 comments on commit 0d7cc0a

Please sign in to comment.