Exemplo n.º 1
0
        private static void writeEbayPricesToJSON(RefVideoCard cardStatistics, int status, FinishedVideoCard almostFinishedVideoCard)
        {
            string line = "";
            string path = @"cashAveragesAppended.JSON";

            if (!File.Exists(path))
            {
                using (StreamWriter sw = File.CreateText(path))
                {
                    if (status == 0)
                    {
                        line = "averageCash: [ ";
                        sw.WriteLine(line);
                    }
                }
            }

            using (System.IO.StreamWriter file = File.AppendText(path))
            {
                string firstBracket = "{";
                string cardId ='"' + "Id" + '"' + ": " + '"' + cardStatistics.GetId() + '"' + ",";
                string cardName = '"' + "Name" + '"' + ": " + '"' + cardStatistics.GetCardName() + '"' + ",";
                string cardAvgHash = '"' + "AvgHash" + '"' + ": " + '"' + almostFinishedVideoCard.getAverageHash() + '"' + ",";
                string cardAvgPrice = '"' + "AvgPrice" + '"' + ": " + '"' + cardStatistics.GetAveragePrice() + '"' + ",";
                string hashForCash = '"' + "HashForCash" + '"' + ": " + '"' + almostFinishedVideoCard.getHashForCash() + '"';

                string lastBracket = "},";
                string lastBracketNoComma = "}";
                file.WriteLine(firstBracket);
                file.WriteLine(cardId);
                file.WriteLine(cardName);
                file.WriteLine(cardAvgHash);
                file.WriteLine(cardAvgPrice);
                file.WriteLine(hashForCash);

                if (status == 2)
                {
                    file.WriteLine(lastBracketNoComma);
                }
                else
                {
                    file.WriteLine(lastBracket);
                }

                if (status == 2)
                {
                    line = "]";
                    file.WriteLine(line);
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //grab cards from excel sheet and compute average hashes
            List<VideoCard> basicInfoList = new List<VideoCard>();
            basicInfoList = readFile(@"C:\radeon.csv");

            //delete JSON values from previous program execution
            deletePreviousResults();

            int status = 0;

            //
            List<VideoCard> cardsFromEbay = new List<VideoCard>();
            List<RefVideoCard> almostDoneCards = calculateAverageHash(basicInfoList);
            RefVideoCard resultCardStats = new RefVideoCard();
            List<RefVideoCard> cardStatsList = new List<RefVideoCard>();
            List<VideoCard> cashAveragedCards = new List<VideoCard>();
            for (int i = 0; i < cardsOfInterest.Length; i++)
            {

                //grab cards from ebay from list of interesting cards
                //cardsFromEbay List = GrabPricesFromEbay("Radeon 5970");
                cardsFromEbay = GrabPricesFromEbay(cardsOfInterest[i]);

                //we now find the AveragePrice, CardCount, and ID of the list of Radeon 5970s
                resultCardStats = calculateAverages(cardsFromEbay, cardsOfInterest[i]);
                cardStatsList.Add(resultCardStats);
                VideoCard cashedCard = new VideoCard();
                cashedCard.SetCardName(resultCardStats.GetCardName());
                cashedCard.SetId(resultCardStats.GetId());
                cashedCard.SetPrice(Convert.ToDouble(resultCardStats.GetAveragePrice()));
                cashAveragedCards.Add(cashedCard);
                //We now append the AveragePrice, CardCount, and ID info to the JSON file (in later version this could be an API call that returns JSON)

                //WriteEbayPricesToSQLServer(resultCardStats.GetId());
            }
            List<FinishedVideoCard> finishedCards = CalculateHashForCash(cashAveragedCards, almostDoneCards);
            for (int i = 0; i < cardsOfInterest.Length; i++)
            {
                if (i == 0)
                {
                    status = 0;
                }
                else if (i == cardsOfInterest.Length - 1)
                {
                    status = 2;
                }
                else
                {
                    status = 1;
                }
                writeEbayPricesToJSON(cardStatsList[i], status, finishedCards[i]);
            }
            Console.WriteLine("It got to here! Yay! :)");
            Console.ReadKey();
        }