<commit_before># rm(list=ls())
# install.packages("RPostgreSQL")
require("RPostgreSQL")
require("ggplot2")
#require("tabplot")
require("gridExtra")

splitdate <- function(stocks) {
  list <- list()
  j <- 0
  dates <- unique(stocks$date)
  for (di in 1:length(dates)) {
    mydate <- dates[di];
    sublist <- subset(stocks, date == mydate)
    j <- j + 1
    list[j] <- list(sublist)
  }
  return (list)
}

splitid <- function(stocks) {
  list <- list()
  j <- 0
  ids <- unique(stocks$id)
  for (ii in 1:length(ids)) {
    myid <- ids[ii];
    sublist <- subset(stocks, id = myid)
    j <- j + 1
    list[j] <- list(sublist)
  }
  return (list)
}

getdforderperiod <- function(df, period) {
	ds <- df
	if (period == 1) {
	  ds <- df[order(-df$period1),]
	}
	if (period == 2) {
	  ds <- df[order(-df$period2),]
	}
	if (period == 3) {
	  ds <- df[order(-df$period3),]
	}
	if (period == 4) {
	  ds <- df[order(-df$period4),]
	}
	if (period == 5) {
	  ds <- df[order(-df$period5),]
	}
return (ds)
}

getlistanddiff <- function(datedstocklists, listid, listdate, count, mytableintervaldays) {
  periodmaps <- matrix(list(), nrow = 5, ncol = (count - 1))
#  stocklistperiod <- matrix(data.frame(), nrow = 5, ncol = count)
  stocklistperiod <- matrix(list(), nrow = 5, ncol = count)
#  stocklistperiod2 <- matrix(1:10, nrow = 5, ncol = count )
#  stocklistperiod <- matrix(list(), nrow = 5, ncol = count)
#  stocklistperiod <- matrix(list(), 5, count)
  for (j in 1:count) {
    print(j);
    for (i in 1:5) {
      hasperiod <- FALSE
      # fix later
      hasperiod <- TRUE
      if (hasperiod) {
      	df <- data.frame(datedstocklists[j])
	ds <- getdforderperiod(df, i)
#        cat("herenr0 ", (nrow(ds)))
#	print("")
	tmp <- list(ds)
#	tmp <- ds
#	cat(i,j)
#	print("here2");
#	str(tmp)
#        stocklistperiod2[i][j] <- 100 + j*10 + i
#        stocklistperiod2[i + 5*(j-1)] <- 100 + j*10 + i
	print(100 + j*10 + i)
        stocklistperiod[i, j] <- tmp
#	stocklistperiod[i + (j-1) * 5] <- tmp
#	if (!identical(stocklistperiod[i][j], tmp)) {
#	print("diff")
#	}
#	if (!identical(stocklistperiod[ + (j-1) * 5], tmp)) {
#	print("diff2")
#	}
#	  print("here2.5");
#        str(stocklistperiod[i][j])
#	print("here2.6")
#	str(stocklistperiod)
#        list2 <- list(ds)
	if (j > 1) {
#	list1 <- stocklistperiod[i][j - 1]
	df1 <- stocklistperiod[i][j - 1]
#        stocklistperiod[i][j] <- list2
#	list2 <- stocklistperiod[i][j]
#	df2 <- stocklistperiod[i][j]
	df2 <- stocklistperiod[i + (j-1)*5]
	df2 <- tmp
#	cat(i,j)
#	print("here3");
#	str(list2)
#	   cat("here", i);
#	   periodmaps[i][j - 1] <- getperiodlist(list1, list2)
#print("bla1")
#str(df1)
#print("bla2")
#str(df2)
#print("bla1")
#print(nrow(data.frame(df1)))
#print("bla2")
#print(nrow(df2))
	   tmplist <- getperiodmap(df1, df2)
#	   print("tmplist")
#	   str(tmplist)
	   periodmaps[i, j - 1] <- list(tmplist)
	}
      }
    }
  }
#  str(stocklistperiod)
#  str(stocklistperiod2)
#  str(periodmaps)
#  str(periodmaps[1][1])
  return(list(periodmaps, stocklistperiod))
}

getstockdate <- function(listdate, date) {
c <- 0
for (i in names(listdate)) {
c <- c + 1
if (date == i) {
return(c)
}
}
return (length(listdate))
}

getlistanddiffperiod <- function(datedstocklists, listid, listdate, count, mytableintervaldays, period) {
  periodmap <- list()
#  stocklistperiod3 <- matrix(list(), nrow = 5, ncol = count)
#  stocklistperiod <- list()
#  stocklistperiod2 <- matrix(1:10, nrow = 5, ncol = count )
  stocklistperiod <- matrix(list(), nrow = 5, ncol = count)
#  stocklistperiod <- matrix(list(), 5, count)
  for (j in 1:count) {
    print(j);
      hasperiod <- FALSE
      # fix later
      hasperiod <- TRUE
      if (hasperiod) {
      	df <- data.frame(datedstocklists[j])
	ds <- getdforderperiod(df, i)
	cat("herenr ", (nrow(ds)))
	print("")
	tmp <- list(ds)
#	tmp <- ds
	cat(period,",",j)
#	print("here2");
#	str(tmp)
#        stocklistperiod3[i][j] <- list(tmp)
# TODO period
        stocklistperiod[[1]][[j]] <- tmp
#	stocklistperiod[j] <- tmp
#	if (!identical(stocklistperiod[i], tmp)) {
#	print("diff")
#	}
#	if (!identical(stocklistperiod[ + (j-1) * 5], tmp)) {
#	print("diff2")
#	}
#	  print("here2.5");
#        str(stocklistperiod[i][j])
#	print("here2.6")
#	str(stocklistperiod)
#        list2 <- list(ds)
	if (j > 1) {
#	list1 <- stocklistperiod[[1]][[j - 1]]
	df1 <- stocklistperiod[j - 1]
#        stocklistperiod[i][j] <- list2
#	list2 <- stocklistperiod[i][j]
#	df2 <- stocklistperiod[i][j]
#	df2 <- stocklistperiod[i]
	df2 <- tmp
#	cat(i,j)
#	print("here3");
#	str(list2)
#	   cat("here", i);
#	   periodmaps[i][j - 1] <- getperiodlist(list1, list2)
#print("bla1")
#str(df1)
#print("bla2")
#str(df2)
#print("bla1")
#print(nrow(data.frame(df1)))
#print("bla2")
#print(nrow(df2))
#print("h1")
#str(df1)
	   tmplist <- getperiodmap(df1, df2)
print("h2")
	   print("tmplist")
#	   str(tmplist)
#	   periodmap[j - 1] <- list(tmplist)
	}
      }
  }
  str(stocklistperiod)
#  str(stocklistperiod2)
#  str(periodmaps)
#  str(periodmaps[1][1])
  return(list(periodmap, stocklistperiod))
}

#getperiodlist <- function(df1, df2) {
getperiodlist <- function(list1, list2) {
#  print("here4");
#  str(list2)
  c <- 0
  list <- list()
  df1 <- data.frame(list1[1])
  df2 <- data.frame(list2[1])
#  str(df1)
#  str(df2)
#  cat("len ", nrow(df2), nrow(df1))
  for (j in 1:nrow(df2)) {
    c <- c + 1
    list[c] <- NA
      for (i in 1:nrow(df1)) {
     	#cat("ids ", df1[j, "id"], df2[i, "id"]);
      if (identical(df1[j, "id"], df2[i, "id"])) {
        list[c] <- i - j
#     	 cat("ident", i-j)
#	 print("")
      }
    }
  }
#  cat("here2 ", length(list))
  return (list)
}


getperiodmap <- function(list1, list2) {
#  print("here4");
#  str(list1)
#  str(list2)
  list <- list()
  df1 <- data.frame(list1[1])
  df2 <- data.frame(list2[1])
#  str(df1)
#  str(df2)
#  cat("len ", nrow(df2), nrow(df1))
  for (j in 1:nrow(df2)) {
    id <- df2[j, "id"]
    list[id] <- NA
      for (i in 1:nrow(df1)) {
     	#cat("ids ", df1[j, "id"], id);
      if (identical(df1[i, "id"], id)) {
        list[id] <- i - j
#     	 cat("ident", i-j)
#	 print("")
      }
    }
  }
#  cat("here2 ", length(list))
  return (list)
}

mytop <- function(datedstocklists, stocklistperiod, periodmaps, period, max) {
#str(stocklistperiod)
list1 <- stocklistperiod
list2 <- periodmaps[[period]][[1]]
#print("len ")
#cat(length(list1),length(list2))
#print("mer")
#str(list2)
#print(class(list2[1][[1]]))
#str(list2[1][1])
list11=stocklistperiod[[1]][1]
list12=stocklistperiod[[1]][2]
list13=stocklistperiod[[1]][3]
list14=stocklistperiod[[1]][4]
list15=stocklistperiod[[1]][5]
list21=list2[[1]]
list211=list21[1]
list22=list2[2]
list23=list2[3]
list24=list2[4]
list25=list2[5]
#str(list211[1])
for (i in 1:max) {
print(sprintf("%-40s %12s %3.2f %3d %3.2f %3d\n", strtrim(list11[[1]]$name[i],38), as.POSIXct(list11[[1]]$date[i], origin="1970-01-01"), list11[[1]]$period1[i], list2[[1]][[i]], list12[[1]]$period1[i], list2[[2]][[i]]))
#cat(list11[[1]]$name[i], " ", as.POSIXct(list11[[1]]$date[i], origin="1970-01-01"), " ", list11[[1]]$period1[i], " ", list2[[1]][[i]], "\n")
}
#print(list1[[1]$name[1])
}

listperiod <- function(list, period, index) {
if (period == 1) {
return (list$period1[index])
}
if (period == 2) {
return (list$period2[index])
}
if (period == 3) {
return (list$period3[index])
}
if (period == 4) {
return (list$period4[index])
}
if (period == 5) {
return (list$period5[index])
}
}

mytopperiod <- function(datedstocklists, stocklistperiod, periodmaps, period, max) {
#str(stocklistperiod)
list1 <- stocklistperiod
cat(period)
list2 <- periodmaps[period, 1][[1]]

#str(list1)
print("len ")
cat(length(list1),length(list2))
print("mer")
#str(list2)
#print(class(list2[1][[1]]))
#str(list2[1][1])
list11 <- stocklistperiod[period, 1][[1]]
list12 <- stocklistperiod[period, 2][[1]]
#str(list211[1])
for (i in 1:max) {
print(sprintf("%3d %-40s %12s %3.2f\n", i, strtrim(list12$name[i],38), as.POSIXct(list12$date[i], origin="1970-01-01"), listperiod(list12, period, i)))
}
for (i in 1:max) {
#print(list11[[1]]$name[i])
#cat(strtrim(list11[[1]]$name[i],38), as.POSIXct(list11[[1]]$date[i], origin="1970-01-01"), list11[[1]]$period1[i], list2[i])
#print(sprintf("%3d %-35s %12s %3.2f %3d %s", i, strtrim(list11$name[i],33), as.POSIXct(list11$date[i], origin="1970-01-01"), list11$period1[i], list2[[i]], list11$id[[i]]))
id <- list12$id[i]
#cat("myid",id)
print(sprintf("%3d %-35s %12s %3.2f %3d %s", i, strtrim(list11$name[i],33), as.POSIXct(list11$date[i], origin="1970-01-01"), listperiod(list11, period, i), list2[[id]], list11$id[[i]]))
#cat(list11[[1]]$name[i], " ", as.POSIXct(list11[[1]]$date[i], origin="1970-01-01"), " ", list11[[1]]$period1[i], " ", list2[[1]][[i]], "\n")
}
#print(list1[[1]$name[1])
}

gettopchart <- function(days, topbottom, stocklistperiod, period) {
mainlist <- stocklistperiod[period, 1][[1]]
oldlist <- stocklistperiod[period, days][[1]]
maindate <- mainlist$date[1]
olddate <- oldlist$date[1]
#for (j in 1:days) {
#if (j > 1) {
#l2 <- listfiltertop(stocklistperiod[[period]][j], stocklistperiod[[period]][[1]], topbottom)
#}
ls <- list()
names <- list()
c <- 0
for (i in 1:topbottom) {
cat("id", mainlist$id[i])
l <- getelem(mainlist$id[i], days, stocklistperiod, period, topbottom)
c <- c + 1
ls[c] <- list(l)
names[c] <- mainlist$name[i]
}
#cat("names", names)
displaychart(ls, names, topbottom, period, maindate, olddate)
}

getchart <- function(days, stocklistperiod, period, ids) {
topbottom <- length(ids)
mainlist <- stocklistperiod[period, 1][[1]]
oldlist <- stocklistperiod[period, days][[1]]
maindate <- mainlist$date[1]
olddate <- oldlist$date[1]
ls <- list()
names <- list()
c <- 0
for (i in 1:topbottom) {
l <- getelem(ids[[i]], days, stocklistperiod, period, topbottom)
str(l[1])
c <- c + 1
ls[c] <- list(l)
listdf <- getelemtup(ids[[i]], days, stocklistperiod, period, topbottom)
df <- data.frame(listdf[[1]])
names[c] <- df$name
}
#cat("names", names)
displaychart(ls, names, topbottom, period, maindate, olddate)
if (topbottom == 2) {
c1 <- c(unlist(ls[1]))
c2 <- c(unlist(ls[2]))
print("here1")
t.test(c1,c2,paired=TRUE)
print("here2")
#t.test(c1,c1,paired=TRUE)
}
}

displaychart <- function(ls, names, topbottom, period, maindate, olddate) {
g_range = range(0, ls, na.rm=TRUE)
print("g_range")
str(g_range)
for (i in 1:topbottom) {
if (i == 1) {
#str(l$id[[1]])
#str(l$name[[2]])
c = c(unlist(ls[1]))
str(c)
plot(c, type="o", ylim=g_range, axes=FALSE, ann=FALSE)
axis(1, at=1:days, lab=c(-(days-1):0))
axis(2, las=1, at=4*0:g_range[2])
box()
#l2 <- getc(l, period)
#str(l[[1]]$period1)
#str(l2)
} else {
cat("count", i)
c = c(unlist(ls[i]))
str(c)
lines(c, type="o")
}
title(main=sprintf("Period %d", period))
title(xlab=sprintf("Time %s - %s", olddate, maindate))
title(ylab="Value")
n = c(unlist(names[1]))
legend(1, g_range[2], names, cex=0.8, pch=21:22, lty=1:2) 
}
#}
}

getrising <- function(days, periodmaps, stocklistperiod, period) {
retl <- list()
for (i in 1:(days - 1)) {<commit_msg>a little cleanup<commit_after># rm(list=ls())
# install.packages("RPostgreSQL")
require("RPostgreSQL")
require("ggplot2")
#require("tabplot")
require("gridExtra")

splitdate <- function(stocks) {
  list <- list()
  j <- 0
  dates <- unique(stocks$date)
  for (di in 1:length(dates)) {
    mydate <- dates[di];
    sublist <- subset(stocks, date == mydate)
    j <- j + 1
    list[j] <- list(sublist)
  }
  return (list)
}

splitid <- function(stocks) {
  list <- list()
  j <- 0
  ids <- unique(stocks$id)
  for (ii in 1:length(ids)) {
    myid <- ids[ii];
    sublist <- subset(stocks, id = myid)
    j <- j + 1
    list[j] <- list(sublist)
  }
  return (list)
}

getdforderperiod <- function(df, period) {
	ds <- df
	if (period == 1) {
	  ds <- df[order(-df$period1),]
	}
	if (period == 2) {
	  ds <- df[order(-df$period2),]
	}
	if (period == 3) {
	  ds <- df[order(-df$period3),]
	}
	if (period == 4) {
	  ds <- df[order(-df$period4),]
	}
	if (period == 5) {
	  ds <- df[order(-df$period5),]
	}
return (ds)
}

getlistanddiff <- function(datedstocklists, listid, listdate, count, mytableintervaldays) {
  periodmaps <- matrix(list(), nrow = 5, ncol = (count - 1))
  stocklistperiod <- matrix(list(), nrow = 5, ncol = count)
  for (j in 1:count) {
    print(j);
    for (i in 1:5) {
      hasperiod <- FALSE
      # fix later
      hasperiod <- TRUE
      if (hasperiod) {
      	df <- data.frame(datedstocklists[j])
	ds <- getdforderperiod(df, i)
#        cat("herenr0 ", (nrow(ds)))
#	print("")
	tmp <- list(ds)
#	tmp <- ds
#	cat(i,j)
#	print("here2");
#	str(tmp)
	print(100 + j*10 + i)
        stocklistperiod[i, j] <- tmp
#        list2 <- list(ds)
	if (j > 1) {
#	list1 <- stocklistperiod[i][j - 1]
	df1 <- stocklistperiod[i][j - 1]
#        stocklistperiod[i][j] <- list2
#	list2 <- stocklistperiod[i][j]
#	df2 <- stocklistperiod[i][j]
	df2 <- stocklistperiod[i + (j-1)*5]
	df2 <- tmp
#	cat(i,j)
#	print("here3");
#	str(list2)
#	   cat("here", i);
#	   periodmaps[i][j - 1] <- getperiodlist(list1, list2)
#print("bla1")
#str(df1)
#print("bla2")
#str(df2)
#print("bla1")
#print(nrow(data.frame(df1)))
#print("bla2")
#print(nrow(df2))
	   tmplist <- getperiodmap(df1, df2)
#	   print("tmplist")
#	   str(tmplist)
	   periodmaps[i, j - 1] <- list(tmplist)
	}
      }
    }
  }
#  str(stocklistperiod)
#  str(stocklistperiod2)
#  str(periodmaps)
#  str(periodmaps[1][1])
  return(list(periodmaps, stocklistperiod))
}

getstockdate <- function(listdate, date) {
c <- 0
for (i in names(listdate)) {
c <- c + 1
if (date == i) {
return(c)
}
}
return (length(listdate))
}

getlistanddiffperiod <- function(datedstocklists, listid, listdate, count, mytableintervaldays, period) {
  periodmap <- list()
  stocklistperiod <- matrix(list(), nrow = 5, ncol = count)
  for (j in 1:count) {
    print(j);
      hasperiod <- FALSE
      # fix later
      hasperiod <- TRUE
      if (hasperiod) {
      	df <- data.frame(datedstocklists[j])
	ds <- getdforderperiod(df, i)
#	cat("herenr ", (nrow(ds)))
	print("")
	tmp <- list(ds)
#	tmp <- ds
#	cat(period,",",j)
#	print("here2");
#	str(tmp)
#        stocklistperiod3[i][j] <- list(tmp)
# TODO period
        stocklistperiod[[1]][[j]] <- tmp
#        list2 <- list(ds)
	if (j > 1) {
#	list1 <- stocklistperiod[[1]][[j - 1]]
	df1 <- stocklistperiod[j - 1]
#        stocklistperiod[i][j] <- list2
	df2 <- tmp
#	cat(i,j)
#	print("here3");
#	str(list2)
#	   cat("here", i);
#	   periodmaps[i][j - 1] <- getperiodlist(list1, list2)
#print("bla1")
#str(df1)
#print("bla2")
#str(df2)
#print("bla1")
#print(nrow(data.frame(df1)))
#print("bla2")
#print(nrow(df2))
#print("h1")
#str(df1)
	   tmplist <- getperiodmap(df1, df2)
print("h2")
	   print("tmplist")
#	   str(tmplist)
#	   periodmap[j - 1] <- list(tmplist)
	}
      }
  }
  str(stocklistperiod)
#  str(stocklistperiod2)
#  str(periodmaps)
#  str(periodmaps[1][1])
  return(list(periodmap, stocklistperiod))
}

#getperiodlist <- function(df1, df2) {
getperiodlist <- function(list1, list2) {
#  print("here4");
#  str(list2)
  c <- 0
  list <- list()
  df1 <- data.frame(list1[1])
  df2 <- data.frame(list2[1])
#  str(df1)
#  str(df2)
#  cat("len ", nrow(df2), nrow(df1))
  for (j in 1:nrow(df2)) {
    c <- c + 1
    list[c] <- NA
      for (i in 1:nrow(df1)) {
     	#cat("ids ", df1[j, "id"], df2[i, "id"]);
      if (identical(df1[j, "id"], df2[i, "id"])) {
        list[c] <- i - j
#     	 cat("ident", i-j)
#	 print("")
      }
    }
  }
#  cat("here2 ", length(list))
  return (list)
}


getperiodmap <- function(list1, list2) {
#  print("here4");
#  str(list1)
#  str(list2)
  list <- list()
  df1 <- data.frame(list1[1])
  df2 <- data.frame(list2[1])
#  str(df1)
#  str(df2)
#  cat("len ", nrow(df2), nrow(df1))
  for (j in 1:nrow(df2)) {
    id <- df2[j, "id"]
    list[id] <- NA
      for (i in 1:nrow(df1)) {
     	#cat("ids ", df1[j, "id"], id);
      if (identical(df1[i, "id"], id)) {
        list[id] <- i - j
#     	 cat("ident", i-j)
#	 print("")
      }
    }
  }
#  cat("here2 ", length(list))
  return (list)
}

mytop <- function(datedstocklists, stocklistperiod, periodmaps, period, max) {
#str(stocklistperiod)
list1 <- stocklistperiod
list2 <- periodmaps[[period]][[1]]
#print("len ")
#cat(length(list1),length(list2))
#print("mer")
#str(list2)
#print(class(list2[1][[1]]))
#str(list2[1][1])
list11=stocklistperiod[[1]][1]
list12=stocklistperiod[[1]][2]
list13=stocklistperiod[[1]][3]
list14=stocklistperiod[[1]][4]
list15=stocklistperiod[[1]][5]
list21=list2[[1]]
list211=list21[1]
list22=list2[2]
list23=list2[3]
list24=list2[4]
list25=list2[5]
#str(list211[1])
for (i in 1:max) {
print(sprintf("%-40s %12s %3.2f %3d %3.2f %3d\n", strtrim(list11[[1]]$name[i],38), as.POSIXct(list11[[1]]$date[i], origin="1970-01-01"), list11[[1]]$period1[i], list2[[1]][[i]], list12[[1]]$period1[i], list2[[2]][[i]]))
#cat(list11[[1]]$name[i], " ", as.POSIXct(list11[[1]]$date[i], origin="1970-01-01"), " ", list11[[1]]$period1[i], " ", list2[[1]][[i]], "\n")
}
#print(list1[[1]$name[1])
}

listperiod <- function(list, period, index) {
if (period == 1) {
return (list$period1[index])
}
if (period == 2) {
return (list$period2[index])
}
if (period == 3) {
return (list$period3[index])
}
if (period == 4) {
return (list$period4[index])
}
if (period == 5) {
return (list$period5[index])
}
}

mytopperiod <- function(datedstocklists, stocklistperiod, periodmaps, period, max) {
#str(stocklistperiod)
list1 <- stocklistperiod
#cat(period)
list2 <- periodmaps[period, 1][[1]]

#str(list1)
#print("len ")
#cat(length(list1),length(list2))
#print("mer")
#str(list2)
#print(class(list2[1][[1]]))
#str(list2[1][1])
list11 <- stocklistperiod[period, 1][[1]]
list12 <- stocklistperiod[period, 2][[1]]
#str(list211[1])
for (i in 1:max) {
print(sprintf("%3d %-40s %12s %3.2f\n", i, strtrim(list12$name[i],38), as.POSIXct(list12$date[i], origin="1970-01-01"), listperiod(list12, period, i)))
}
for (i in 1:max) {
#print(list11[[1]]$name[i])
#cat(strtrim(list11[[1]]$name[i],38), as.POSIXct(list11[[1]]$date[i], origin="1970-01-01"), list11[[1]]$period1[i], list2[i])
#print(sprintf("%3d %-35s %12s %3.2f %3d %s", i, strtrim(list11$name[i],33), as.POSIXct(list11$date[i], origin="1970-01-01"), list11$period1[i], list2[[i]], list11$id[[i]]))
id <- list12$id[i]
#cat("myid",id)
print(sprintf("%3d %-35s %12s %3.2f %3d %s", i, strtrim(list11$name[i],33), as.POSIXct(list11$date[i], origin="1970-01-01"), listperiod(list11, period, i), list2[[id]], list11$id[[i]]))
#cat(list11[[1]]$name[i], " ", as.POSIXct(list11[[1]]$date[i], origin="1970-01-01"), " ", list11[[1]]$period1[i], " ", list2[[1]][[i]], "\n")
}
#print(list1[[1]$name[1])
}

gettopchart <- function(days, topbottom, stocklistperiod, period) {
mainlist <- stocklistperiod[period, 1][[1]]
oldlist <- stocklistperiod[period, days][[1]]
maindate <- mainlist$date[1]
olddate <- oldlist$date[1]
#for (j in 1:days) {
#if (j > 1) {
#l2 <- listfiltertop(stocklistperiod[[period]][j], stocklistperiod[[period]][[1]], topbottom)
#}
ls <- list()
names <- list()
c <- 0
for (i in 1:topbottom) {
#cat("id", mainlist$id[i])
l <- getelem(mainlist$id[i], days, stocklistperiod, period, topbottom)
c <- c + 1
ls[c] <- list(l)
names[c] <- mainlist$name[i]
}
#cat("names", names)
displaychart(ls, names, topbottom, period, maindate, olddate)
}

getchart <- function(days, stocklistperiod, period, ids) {
topbottom <- length(ids)
mainlist <- stocklistperiod[period, 1][[1]]
oldlist <- stocklistperiod[period, days][[1]]
maindate <- mainlist$date[1]
olddate <- oldlist$date[1]
ls <- list()
names <- list()
c <- 0
for (i in 1:topbottom) {
l <- getelem(ids[[i]], days, stocklistperiod, period, topbottom)
str(l[1])
c <- c + 1
ls[c] <- list(l)
listdf <- getelemtup(ids[[i]], days, stocklistperiod, period, topbottom)
df <- data.frame(listdf[[1]])
names[c] <- df$name
}
#cat("names", names)
displaychart(ls, names, topbottom, period, maindate, olddate)
if (topbottom == 2) {
c1 <- c(unlist(ls[1]))
c2 <- c(unlist(ls[2]))
print("here1")
t.test(c1,c2,paired=TRUE)
print("here2")
#t.test(c1,c1,paired=TRUE)
}
}

displaychart <- function(ls, names, topbottom, period, maindate, olddate) {
g_range = range(0, ls, na.rm=TRUE)
print("g_range")
str(g_range)
for (i in 1:topbottom) {
if (i == 1) {
#str(l$id[[1]])
#str(l$name[[2]])
c = c(unlist(ls[1]))
str(c)
plot(c, type="o", ylim=g_range, axes=FALSE, ann=FALSE)
axis(1, at=1:days, lab=c(-(days-1):0))
axis(2, las=1, at=4*0:g_range[2])
box()
#l2 <- getc(l, period)
#str(l[[1]]$period1)
#str(l2)
} else {
#cat("count", i)
c = c(unlist(ls[i]))
#str(c)
lines(c, type="o")
}
title(main=sprintf("Period %d", period))
title(xlab=sprintf("Time %s - %s", olddate, maindate))
title(ylab="Value")
n = c(unlist(names[1]))
legend(1, g_range[2], names, cex=0.8, pch=21:22, lty=1:2) 
}
#}
}

getrising <- function(days, periodmaps, stocklistperiod, period) {
retl <- list()
for (i in 1:(days - 1)) {
{'fraction_non_alphanumeric': 0.23042998897464168, 'fraction_numerical': 0.050668711950529695, 'mean_word_length': 4.34785952319918, 'pattern_counts': {'":': 0, '<': 270, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '428082', 'n_tokens_mistral': 9609, 'n_tokens_neox': 8956, 'n_words': 1683}