public Dictionary <string, JOffer> GetMap(List <SupplierNew> offers) { Dictionary <string, JOffer> dayOffers = new Dictionary <string, JOffer>(); foreach (SupplierNew o in offers) { string offerKey = o.Category + o.Transmission; if ((offerKey.Equals("People CarrierM") && o.Seats != 9) || o.Category.Contains("skip")) { AddCar(o); continue; } if (dayOffers.ContainsKey(offerKey)) { dayOffers[offerKey].AddSupplier(o); } else { dayOffers[offerKey] = new JOffer(); dayOffers[offerKey].AddSupplier(o); } } return(dayOffers); }
public JOffer GetMinOffer(List <JOffer> offers) { float minPrice = 999999; String minSupplier = null; float minGMPrice = 9999999; String minGMSupplier = null; foreach (JOffer of in offers) { String supplier = of.GetSupplier().ToLower(); if (!(supplier.Equals("green motion")) && (of.GetPrice() < minPrice)) { minPrice = of.GetPrice(); minSupplier = of.GetSupplier(); } else if (supplier.Equals("green motion") && (of.GetPrice() < minGMPrice)) { minGMPrice = of.GetPrice(); minGMSupplier = "GM"; } } JOffer offer = new JOffer(); offer.SetPrice(minPrice); offer.SetSupplier(minSupplier); offer.SetGMPrice(minGMPrice); offer.SetGM(minGMSupplier); offer.SetSiteName(offer.GetSiteName()); return(offer); }
public void CalculatePricesTest() { Dictionary <string, Dictionary <string, JOffer> > pdfRates = new Rates().GetRates(sf, out site); string brokerName = "JIG"; // for (int i = 0; i < Classes.Count(); i++) { PricingHelper ph = new PricingHelper(); List <JOffer> categoryOffers = new PricingHelper().GetMiniRatesList(pdfRates, "EconomyA"); List <JOffer> higherOffers = new PricingHelper().GetMiniRatesList(pdfRates, "CompactM"); List <float> fuseRates = new CsvHelper("314141").GetFuseRates(brokerName); PricingClass[] classes = new PricingClass[5]; PricingHelper hp = new PricingHelper(new PricingModel(), classes); List <float> priceList = hp.CalculatePrices(categoryOffers, higherOffers, fuseRates, brokerName); Console.WriteLine("-----------------"); for (int i = 0; i < priceList.Count; i++) { JOffer tempOffer = categoryOffers.Count > i?categoryOffers.ElementAt(i) : null; float price = tempOffer != null?tempOffer.GetMinPrice() : 0; float gmPrice = tempOffer != null?tempOffer.GetMinGmPrice() : 0; Console.WriteLine(i + " price " + price + " gmprice " + gmPrice + " fuse: " + fuseRates.ElementAt(i) + " new price: " + priceList.ElementAt(i)); } Console.WriteLine("-----------------"); Console.ReadLine(); } }
public List <JOffer> GetScannerRates(string url) { WebRequest request = WebRequest.Create(url); // If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials; // Get the response. if (addProxy) { WebProxy proxy = new WebProxy(ipStr, port); proxy.Credentials = new NetworkCredential(user, pass); request.Proxy = proxy; } WebResponse response = request.GetResponse(); // Display the status. //Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. int remove = Regex.Match(responseFromServer, "(\\w)*\\[\\],").Captures[0].Index + 3;; string subJson = "{" + responseFromServer.Substring(remove, responseFromServer.Length - 2 - remove); JToken entireJson = JToken.Parse(subJson); JArray vehVendorAvails = entireJson["VehAvailRSCore"]["VehVendorAvails"].Value <JArray>();// Get suppliers Console.WriteLine(vehVendorAvails.Count); List <JOffer> offers = new List <JOffer>(); foreach (var item in vehVendorAvails) { string supplier = item["Vendor"]["@CompanyShortName"].ToString(); foreach (var vehicle in item["VehAvails"]) { string category = vehicle["VehAvailCore"]["Vehicle"]["@Code"].ToString(); // category string price = vehicle["VehAvailCore"]["TotalCharge"]["@RateTotalAmount"].ToString(); //price JOffer offer = new JOffer(supplier, price); offer.SetCategory(category); offers.Add(offer); //if (offer.category.Equals("skip")) // Debug.WriteLine("Model" + vehicle["VehAvailCore"]["Vehicle"]["VehMakeModel"]["@Name"] + "Cateory " + category);//Model } } // Clean up the streams and the response. reader.Close(); response.Close(); return(offers); }
public List <JOffer> GetNorwRates(string url) { WebRequest request = WebRequest.Create(url);// Create a request for the URL. if (addProxy) { WebProxy proxy = new WebProxy(ipStr, port); proxy.Credentials = new NetworkCredential(user, pass); request.Proxy = proxy; } using (WebResponse response = request.GetResponse()) { using (Stream dataStream = response.GetResponseStream()) // Get the stream containing content returned by the server. { StreamReader reader = new StreamReader(dataStream); // Open the stream using a StreamReader for easy access. string responseFromServer = reader.ReadToEnd(); // Read the content. int remove = Regex.Match(responseFromServer, "(\\w)*\\[\\],").Captures[0].Index + 3; string subJson = "{" + responseFromServer.Substring(remove, responseFromServer.Length - 2 - remove); JToken entireJson = JToken.Parse(subJson); JArray vehVendorAvails = entireJson["VehAvailRSCore"]["VehVendorAvails"].Value <JArray>();// Get suppliers Console.WriteLine(vehVendorAvails.Count); List <JOffer> offers = new List <JOffer>(); foreach (var item in vehVendorAvails) { string supplier = item["Vendor"]["@CompanyShortName"].ToString(); foreach (var vehicle in item["VehAvails"]) { string category = vehicle["VehAvailCore"]["Vehicle"]["@Code"].ToString(); // category string price = vehicle["VehAvailCore"]["TotalCharge"]["@RateTotalAmount"].ToString(); //price JOffer offer = new JOffer(supplier, price); offer.SetCategory(category); offers.Add(offer); } } reader.Close();// Clean up the streams and the response. return(offers); } } }
public List <JOffer> GetVehicleOffers(string jsonStr) { JToken entireJson = JToken.Parse(jsonStr); JArray vehVendorAvails = entireJson["cars"].Value <JArray>();// Get suppliers List <JOffer> offers = new List <JOffer>(); foreach (var item in vehVendorAvails) { string supplier = item["Supplier"]["name"].ToString(); string category = item["Car"]["internal_class"].ToString(); string price = item["Price"]["original_price"].ToString(); JOffer offer = new JOffer(supplier, price); offer.SetCategory(category); offers.Add(offer); } return(offers); }
public List <JOffer> GetAtlassOffers(string siteSource) { Console.WriteLine("-->GetOfferCount Started"); try { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(siteSource); Console.WriteLine("--<GetOffer attr Started"); HtmlNodeCollection offersFound = doc.DocumentNode.SelectNodes(".//div[@data-price]"); //HtmlNode offerFound = doc.DocumentNode.SelectNodes(".//div[@data-price]"); List <JOffer> offers = new List <JOffer>(); if (offersFound != null) { foreach (HtmlNode divNode in offersFound) { HtmlAttribute price = divNode.Attributes["data-price"]; HtmlAttribute category = divNode.Attributes["data-acriss"]; //HtmlAttribute supplier = supplierInfo.Attributes["data-acriss"]; string supplier = divNode.SelectNodes(".//div[@class='overlay']//ul//li//a").ElementAt(2).Attributes["href"].Value.Split('/').Last(); JOffer offer = new JOffer(Atlass.GetSupplier(supplier), price.Value); offer.SetCategory(category.Value); offers.Add(offer); } Console.WriteLine("--<GetOffer attr Finished"); return(offers); } else { return(offers); } } catch (Exception e) { Debug.WriteLine("Offers not found"); return(null); } }
public string GetExcel(SiteBase s, Dictionary <string, Dictionary <string, JOffer> > offerMap) { FileInfo template = new FileInfo(HttpContext.Current.Server.MapPath(@"\Content\ExcelPackageTemplate.xlsx")); string filename = @"\output\" + s.GetTitle() + s.GetPuMonth() + "-" + s.GetPuDay() + s.GetCity() + ".xlsx"; FileInfo newFile = new FileInfo(HttpContext.Current.Server.MapPath(filename)); using (ExcelPackage excelPackage = new ExcelPackage(newFile, template)) { ExcelWorkbook myWorkbook = excelPackage.Workbook; // Getting the complete workbook... ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Rates"]; // Getting the worksheet by its name... int rowNum = 2; DateTime doDate = new DateTime(Convert.ToInt32(s.GetPuYear()), Convert.ToInt32(s.GetPuMonth()), Convert.ToInt32(s.GetPuDay())); foreach (string link in offerMap.Keys.ToList()) { Dictionary <string, JOffer> map = offerMap[link]; List <JOffer> offers = OffersToArray(map, link); int colNum = 2; myWorksheet.Cells[rowNum, 1].Value = s.GetPuMonth() + "-" + s.GetPuDay() + "/" + doDate.AddDays(rowNum - 1).Day + "\n" + (rowNum - 1); for (int i = 0; i < offers.Count; i++) { myWorksheet.Row(rowNum).Height = 50; //myWorksheet.Row(rowNum + 1).Height = 50; //myWorksheet.Row(rowNum + 2).Height = 50; JOffer o = offers.ElementAt(i); SupplierNew other = o.GetOtherSupplier(); SupplierNew gm = o.GetGmSupplier(); SupplierNew cr = o.GetCrSupplier(); myWorksheet.Cells[rowNum, colNum].Value = (gm != null ? gm.ToString() : ""); myWorksheet.Cells[rowNum, colNum + 1].Value = (cr != null ? cr.ToString() : ""); myWorksheet.Cells[rowNum, colNum + 2].Value = (other != null ? other.ToString() : ""); colNum += 3; } rowNum++; } excelPackage.Save();// Saving the change... return(filename); } }
public List <JOffer> GetExpediaOffers(string jsonStr) { JToken entireJson = JToken.Parse(jsonStr); JArray vehVendorAvails = entireJson["offers"].Value <JArray>();// Get suppliers Console.WriteLine(vehVendorAvails.Count); List <JOffer> offers = new List <JOffer>(); foreach (var item in vehVendorAvails) { string supplier = item["vendor"]["name"].ToString(); string category = item["vehicle"]["classification"]["code"].ToString() + item["vehicle"]["transmission"].ToString()[0] + "R"; string price = item["fare"]["total"]["value"].ToString(); JOffer offer = new JOffer(supplier, price); offer.SetCategory(category); offers.Add(offer); } return(offers); }
public List <JOffer> GetBookingOffers(string jsonStr) { JToken entireJson = JToken.Parse(jsonStr); JArray vehVendorAvails = entireJson["cars"].Value <JArray>();// Get suppliers Console.WriteLine(vehVendorAvails.Count); List <JOffer> offers = new List <JOffer>(); foreach (var item in vehVendorAvails) { string supplier = item["supplier"]["name"].ToString(); string category = item["car"]["classCode"].ToString(); string price = item["price"]["total"].ToString(); JOffer offer = new JOffer(supplier, price); offer.SetCategory(category); offers.Add(offer); } return(offers); }
private List <JOffer> GeHigherOffers() { List <JOffer> offers = new List <JOffer>(); JOffer o1 = new JOffer("Budget", 35.2f); o1.SetGM("Green"); o1.SetGMPrice(23f); offers.Add(o1); o1 = new JOffer("Avis", 46.2f); o1.SetGM("Green"); o1.SetGMPrice(30f); offers.Add(o1); o1 = new JOffer("SIxt", 58.2f); o1.SetGM("Green"); o1.SetGMPrice(55f); offers.Add(o1); return(offers); }
public List <JOffer> ExtractOffers(HtmlNodeCollection resultGroups) { List <JOffer> offers = new List <JOffer>(); if (resultGroups != null) { foreach (HtmlNode mainNode in resultGroups) { //price ------------------------------------------------ string[] priceStrgs = { ".//p[@class='now ']", ".//p[@class='now']", ".//span[@class='carResultRow_Price-now']" }; HtmlNode priceNode = null; string price = string.Empty; for (int i = 0; i < priceStrgs.Count() && priceNode == null; i++) { priceNode = mainNode.SelectSingleNode(priceStrgs[i]); if (priceNode != null) { price = priceNode.InnerText; } } if (priceNode == null) { Debug.WriteLine("--------------->Price not pursed----------------"); } //supplier ------------------------------------------------ string supplier = string.Empty; string[] supplierStrgs = { ".//div[@class='supplier_id']/img", ".//div[@class='col dbl info-box supplier']/img", ".//div[@class='carResultRow_OfferInfo_Supplier-wrap']/img" }; HtmlNode supplierNode = null; for (int i = 0; i < supplierStrgs.Count() && supplierNode == null; i++) { supplierNode = mainNode.SelectSingleNode(supplierStrgs[i]); if (supplierNode != null) { supplier = supplierNode.Attributes["title"].Value; } } if (supplierNode == null) { Debug.WriteLine("Suppliernot pursed -------------------------------"); } //category ------------------------------------------------ string category = string.Empty; string[] categoryStrs = { ".//p[contains(@class,'bg-yellow-5')]", ".//span[contains(@class,'class mini')]", ".//span[contains(@class,'carResultRow_CarSpec_CarCategory')]" }; HtmlNode categoryNode = null; for (int i = 0; i <= categoryStrs.Count() && categoryNode == null; i++) { categoryNode = mainNode.SelectSingleNode(categoryStrs[i]); if (categoryNode != null) { category = categoryNode.InnerText; } } if (categoryNode == null) { Debug.WriteLine("-------------> category not pursed"); } //transmission ------------------------------------------------ string transm = string.Empty; string[] transmStrgs = { ".//li[contains(@class,'result_trans')]", ".//span[contains(@class,'class mini')]", ".//ul[contains(@class, 'carResultRow_CarSpec-tick')]/li[2]" }; HtmlNode transmNode = null; for (int i = 0; i < transmStrgs.Count() && transmNode == null; i++) { transmNode = mainNode.SelectSingleNode(transmStrgs[i]); if (transmNode != null) { transm = transmNode.InnerText; } } if (transmNode == null) { Debug.WriteLine("-------------> transm not pursed"); } //seats string seats = string.Empty; string[] seatsStrgs = { ".//li[contains(@class,'result_seats')]", ".//span[contains(@class,'class mini')]", ".//li[contains(@class,'carResultRow_CarSpec_Seats')]" }; HtmlNode seatsNode = null; for (int i = 0; i < seatsStrgs.Count() && seatsNode == null; i++) { seatsNode = mainNode.SelectSingleNode(seatsStrgs[i]); if (seatsNode != null) { seats = seatsNode.InnerText; } } if (seatsNode == null) { Debug.WriteLine("-------------> seats not pursed"); } //car name ------------------------------------------------ string carName = string.Empty; string[] carNameStrgs = { ".//td[contains(@class,'carResultRow_CarSpec')]" }; HtmlNode carNameNode = null; for (int i = 0; i < carNameStrgs.Count() && carNameNode == null; i++) { carNameNode = mainNode.SelectSingleNode(carNameStrgs[i]); if (carNameNode != null) { carName = carNameNode.InnerText.Split('&')[0]; } } if (carNameNode == null) { Debug.WriteLine("-------------> carName not pursed"); } JOffer o = new JOffer(supplier, price, category, transm, seats); if (carName.ToLower().Contains("renault clio estate") && o.transmission.Equals("A")) { o.category = "Economy"; } offers.Add(o); } } else { Debug.WriteLine("JSOURCEREDAER 0 offer number "); } return(offers); }
private List <JOffer> GetTestOffers() { List <JOffer> offers = new List <JOffer>(); JOffer o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(23f); offers.Add(o1); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(30f); offers.Add(o1); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(23f); offers.Add(o1); o1 = new JOffer("Europcar", 61.2f); o1.SetGM("Green"); o1.SetGMPrice(88f); offers.Add(o1); o1 = new JOffer("Europcar", 61.2f); offers.Add(o1); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(88f); offers.Add(o1); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(88f); offers.Add(o1); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(88f); offers.Add(o1); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(108f); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(118f); offers.Add(o1); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(130f); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(154f); offers.Add(o1); o1 = new JOffer(); o1.SetGM("Green"); o1.SetGMPrice(180f); o1 = new JOffer(); o1.SetGM(""); o1.SetGMPrice(0); o1 = new JOffer(); o1.SetGM(""); o1.SetGMPrice(0); offers.Add(o1); offers.Add(o1); offers.Add(o1); return(offers); }
public void AddRow(JOffer[] offers) { try { PdfPCell cell = new PdfPCell(new Phrase(puMonth + "-" + puDay + "/" + doDate.AddDays(dayNum).Day + "\n" + dayNum, font)); dayNum++; cell.HorizontalAlignment = 1; cell.VerticalAlignment = 1; table.AddCell(cell); for (int i = 0; i < offers.Length; i++) { JOffer o = offers[i]; cell = new PdfPCell(new Phrase(o.GetOffer(), font)); var chunk = new Chunk(o.GetOffer(), font); SupplierNew other = o.GetOtherSupplier(); SupplierNew gm = o.GetGmSupplier(); SupplierNew cr = o.GetCrSupplier(); SupplierNew best = o.GetBestSupplier(); if (other != null) { AddSuppliers(other.SupplierName);//best } if (best != null) { AddSuppliers(best.SupplierName);//best } if (cr != null) { AddSuppliers(cr.SupplierName);// carsrent } if (i == 0) { chunk.SetAnchor(o.GetSiteName());// if mini add site name } cell.AddElement(chunk); if (gm != null && other != null && other.Price > gm.Price && gm.Price > 0) { cell.BackgroundColor = new BaseColor(77, 148, 255); if (other.Price - gm.Price < 2.5f && other.Price - gm.Price > 0) { cell.BackgroundColor = new BaseColor(255, 255, 179); if (other.Price - gm.Price < 1.5f && other.Price - gm.Price > 0) { cell.BackgroundColor = new BaseColor(128, 255, 128); } } } else { cell.BackgroundColor = new BaseColor(255, 102, 102); } table.AddCell(cell); } table.CompleteRow(); } catch (Exception e) { Log.Instance.Warn("-PdfBuilder.AddRow-" + e.InnerException + e.Message); } }