#TASK 1 
#1.1
climateData<-read.csv("climate.csv",header=TRUE,stringsAsFactors=FALSE)
climateData$climate.Type<-factor(climateData$climate.Type)
WuhanData<-read.csv("Wuhan Processed.csv",header=TRUE,stringsAsFactors=FALSE)
WuhanData$Wuhan.Type<-factor(WuhanData$Wuhan.Type)
#View(climateData)
#View(WuhanData)
city<-c("Swansea","Swansea","Swansea","Swansea","Swansea","Swansea","Swansea","Wuhan","Wuhan","Wuhan","Wuhan","Wuhan","Wuhan","Wuhan")
climate_temp<-rbind(climateData,WuhanData)
climate<-cbind(city,climate_temp)
#1.2
Srainfall1<-NULL
Ssunshine1<-NULL
Wrainfall1<-NULL
Wsunshine1<-NULL
Srainfall1<-climate[4,3:14]
Ssunshine1<-climate[7,3:14]
Wrainfall1<-climate[11,3:14]
Wsunshine1<-climate[14,3:14]
Srainfall<-sum(Srainfall1,na.rm=TRUE)
Ssunshine<-sum(Ssunshine1,na.rm=TRUE)
Wrainfall<-sum(Wrainfall1,na.rm=TRUE)
Wsunshine<-sum(Wsunshine1,na.rm=TRUE)
cumulative_rainfall<-c(Srainfall,Wrainfall)
cumulative_number_of_hours_of_sunshine<-c(Ssunshine,Wsunshine)
cumulativeData1<-data.frame(cumulative_rainfall,cumulative_number_of_hours_of_sunshine,stringsAsFactors=FALSE)
city1<-c("Swansea","Wuhan")
cumulativeData<-cbind(city1,cumulativeData1)
View(cumulativeData)
#1.3
displayGraph<-function(x,y)
  
{
  city_temp<-NULL
  temp_value<-NULL
    for(k in 1:14 )            #Find the corresponding number
    {
      city_temp<-climate[k,1]
      if (x==city_temp)
      {  
      temp_value<-c(temp_value,k)
      
  }
    }

temp_value2<-NULL
value<-NULL
data_plot<-NULL
for(k in 1:7 )            #Find the corresponding number
{
  
  data_temp<-climate[temp_value[k],2]
  if (y==data_temp)
  {  value<-temp_value[k]
  data_plot<-climate[value,3:14]
  month<-c(1,2,3,4,5,6,7,8,9,10,11,12)
  plot(month,data_plot,type= "b")
  
  }
}}
displayGraph("Wuhan","Humidity(%)")
displayGraph("Swansea","Precipitation / Rainfall mm")
#1.4

compareCities<-function(start_month,end_month,p1,p2)
{data_p1<-NULL
 data_p1<-NULL
  start_temp<-NULL
  end_temp<-NULL
  temp1<-NULL
  temp2<-NULL
  start_temp<-c(start_month+1)
  end_temp<-c(end_month+1)
   
    for(i in 1:7)            #Find the corresponding number
    {
      temp<-WuhanData[i,1]
      if (p1==temp)
      {  
        temp1<-i
        print(temp1)
      }}
    for(k in 1:7)
    {  temp<-WuhanData[k,1]
      if (p2==temp)
     {  
        temp2<-k
        print(temp2)
     }
      
    }
 
  data_p1<-c(WuhanData[temp1,start_temp:end_temp])
  data_p2<-c(WuhanData[temp2,start_temp:end_temp])
  pp2<-as.matrix(data_p2)
  
  month<-(start_month:end_month)
  if(p1=="Avg. Temperature ˇăC"||p1=="Humidity(%)")
  {
    plot(month,data_p1,type= "o",col=c("yellow"))}
    else
    {#plot(month,data_p1,type= "o")}
      barplot(as.numeric(data_p1),col="yellow")}
    
  if(p2=="Avg. Temperature ˇăC"||p2=="Humidity(%)")
    {par(new=TRUE)
    plot(month,data_p2,type= "o",col=c("blue"))}
    else
     {  par(new=TRUE)
       #plot(month,data_p2,type= "o")}
        barplot(as.numeric(data_p2),col="blue")}
  legend("topright", inset=.01,title="weather parameters", c("data_p1","data_p2"), lty=c(1, 2), col=c("yellow", "blue"))
}

compareCities(1,12,"Rainy days (d)","Humidity(%)")

