Exemple #1
0
        private Dictionary <int, double> GetPhoneScores(List <int> ids)
        {
            Dictionary <int, double> AllScores = new Dictionary <int, double>();

            foreach (int id in ids)
            {
                List <PhoneProperties> ComparisonSpecs = Hardware.Where(x => x.ConfigId != id).ToList();
                PhoneProperties        CurrentSpecs    = Hardware.FirstOrDefault(x => x.ConfigId == id);

                System.Diagnostics.Debug.WriteLine($"");

                System.Diagnostics.Debug.WriteLine($"ALGORITHM: Checking {CurrentSpecs.Brand} {CurrentSpecs.Model}");


                List <double> CurrentPhoneScores = new List <double>();

                foreach (PhoneProperties p in ComparisonSpecs)
                {
                    System.Diagnostics.Debug.WriteLine($"ALGORITHM: Calculating percent difference between {CurrentSpecs.Brand} and {p.Brand} -- {GetPercentDifference(CurrentSpecs, p)}");
                    CurrentPhoneScores.Add(GetPercentDifference(CurrentSpecs, p));
                }

                double phoneScore = CurrentPhoneScores.Average();

                AllScores.Add(id, phoneScore);
            }

            foreach (var i in AllScores)
            {
                System.Diagnostics.Debug.WriteLine($"PHONE ID: {i.Key}; PHONE SCORE: {i.Value}");
            }

            return(AllScores);
        }
        public async Task <IActionResult> Edit(int id, [Bind("ConfigId,Brand,Model,Storage,Cpu,CpuType,CpuSpeed,RAM,HasGPU,HeadphoneOutput,Capable5g,FrontCameraMegapixel,BackCameraMegapixel,BatteryCapacity,ExchangableBattery,Depth,Height,Width,Weight,WirelessCharging,WirelessStandard,DualSim,SimCard,FastCharging,WaterResistance,ReleaseYear")] PhoneProperties phoneProperties)
        {
            if (id != phoneProperties.ConfigId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(phoneProperties);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhonePropertiesExists(phoneProperties.ConfigId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(phoneProperties));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ConfigId,Brand,Model,Storage,HasMemoryCardReader,Cpu,CpuCoreCount,CpuSpeed,RAM,HasGPU,GPU,HeadphoneOutput,Is2gCapable,Is3gCapable,Is4gCapable,Is5gCapable,HasBluetooth,HasGPS,IsWifiCapable,BuiltInCamera,FrontCamera,FrontCameraMegapixel,BackCameraMegapixel,MaximumLensApeture,RearCameraCount,CanRecordVideo,MaxFramerateMaxResolution,MaxFramerateMinResolution,BatteryCapacity,ExchangableBattery,Depth,Height,Width,Weight,WirelessCharging,WirelessStandard,DualSim,SimCard,FastCharging,WaterResistance,OriginalPrice,ReleaseDate,ProductPage,isSelected")] PhoneProperties phoneProperties)
        {
            if (id != phoneProperties.ConfigId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(phoneProperties);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhonePropertiesExists(phoneProperties.ConfigId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(phoneProperties));
        }
        public async Task <IActionResult> Create([Bind("ConfigId,Brand,Model,Storage,Cpu,CpuType,CpuSpeed,RAM,HasGPU,HeadphoneOutput,Capable5g,FrontCameraMegapixel,BackCameraMegapixel,BatteryCapacity,ExchangableBattery,Depth,Height,Width,Weight,WirelessCharging,WirelessStandard,DualSim,SimCard,FastCharging,WaterResistance,ReleaseYear")] PhoneProperties phoneProperties)
        {
            if (ModelState.IsValid)
            {
                _context.Add(phoneProperties);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(phoneProperties));
        }
Exemple #5
0
        private double GetPercentDifference(PhoneProperties phone, PhoneProperties comparisonPhone)
        {
            int    mainStorage = phone.Storage;
            int    compStorage = comparisonPhone.Storage;
            double storageDiff = GetPercentDifference(mainStorage, compStorage);

            int    mainCpuCount = phone.CpuCoreCount;
            int    compCpuCount = comparisonPhone.CpuCoreCount;
            double cpuCountDiff = GetPercentDifference(mainCpuCount, compCpuCount);

            double mainCpuSpeed = phone.CpuSpeed;
            double compCpuSpeed = comparisonPhone.CpuSpeed;
            double cpuSpeedDiff = GetPercentDifference(mainCpuSpeed, compCpuSpeed);

            int    mainRam = phone.RAM;
            int    compRam = comparisonPhone.RAM;
            double ramDiff = GetPercentDifference(mainRam, compRam);

            int    mainFrontCameraMgpx = phone.FrontCameraMegapixel;
            int    compFrontCameraMgpx = comparisonPhone.FrontCameraMegapixel;
            double frontCameraMgpxDiff = GetPercentDifference(mainFrontCameraMgpx, compFrontCameraMgpx);

            int    mainBackCameraMgpx = phone.BackCameraMegapixel;
            int    compBackCameraMgpx = comparisonPhone.BackCameraMegapixel;
            double backCameraMgpxDiff = GetPercentDifference(mainBackCameraMgpx, compBackCameraMgpx);

            int    mainRearCamera     = phone.RearCameraCount;
            int    compRearCameraMgpx = comparisonPhone.RearCameraCount;
            double rearCameraDiff     = GetPercentDifference(mainRearCamera, compRearCameraMgpx);

            System.Diagnostics.Debug.WriteLine($"DIFF: {storageDiff} {cpuCountDiff} {cpuSpeedDiff} {ramDiff} {frontCameraMgpxDiff} {backCameraMgpxDiff} {rearCameraDiff}");

            return(new List <double> {
                storageDiff, cpuCountDiff, cpuSpeedDiff, ramDiff, frontCameraMgpxDiff, backCameraMgpxDiff, rearCameraDiff
            }.Average());
        }