



@names = ("GOOG","MSFT","MO","AAPL","AIG", "BSC", "AMZN", "AMD", "T", "ADBE", "ANF", "GS","BKS", "HPQ","MER", "LMT", "HON", "TWX", "GT", "NYT", "TXN", "NATI"
, "QCOM", "LEH", "VZ", "VOD", "S", "IBM",  "YHOO", "DIS", "WMT", "WAG", "SI", "BLK", "XLNX", "ADI", "BAC", "INTC", "WB", "LHL.F" ,"DELL", "TTM", "INFY", "TCS
.NS", "CTSH", "ACN", "CSCO", "DFG", "JPM", "SNE", "PHG", "JNJ","SLB", "C", "DB", "BSC", "UBS");
open(pred,">pred.php");
open(f,"<$ARGV[0]");

print pred <<PHP;
<?php
\$con = mysql_connect("localhost","group802","Cor\@538");
if (!\$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("group802", \$con);
PHP
@data = ();
foreach(@names) {

	for($i = 0;$i < 13;$i++) {
		$data[$i] = <f>;	
	        chomp $data[$i];
		$data[$i] =~ s/\n//g;
		$data[$i] =~ s/\r//g;
	}
     	
	if($data[5] < 0)
	{
		$dec = "SELL";
	}
	else {
	if($data[5] > 0)
	{
		$dec = "BUY";
	}
	else {
		$dec = "HOLD";
	}
	}
	
	print pred "mysql_query(\"INSERT into prediction values(\'$_\',\'$dec\',\'$data[3]\',\'$data[4]\',\'$data[5]\')\");\n";
	$qq = "mysql_query(\"INSERT into pre values(\'$_\'";
        for($i = 0;$i < 7;$i++) {
		$qq .= ",\'$data[6+$i]\'";
	}
	print pred $qq.")\");\n";
	
	
	@line1 = split(/ /,$data[0]);
	@line2 = split(/ /,$data[1]);
	@line3 = split(/ /,$data[2]);
	
	splice( @line1,1,1);
	splice( @line2,1,1);
	splice( @line3,1,1);
	$" = "\',\'";
	print pred "mysql_query(\"INSERT into regression values(\'$_\',\'"."@line1"."\')\");\n";
	print pred "mysql_query(\"INSERT into regression values(\'$_\',\'"."@line2"."\')\");\n";
	print pred "mysql_query(\"INSERT into regression values(\'$_\',\'"."@line3"."\')\");\n";

       $dum =  <f>;	
}

print pred "mysql_close(\$con);\n?>" ;
