将嵌套字典转换为数据框

时间:2018-09-05 10:44:56

标签: python dictionary nested

我有以下列表:

 public async Task<IActionResult> Create(DonorViewModel be, IFormFile pic)
        {
            be.RegCampId = Convert.ToInt32(TempData["Camp"]);
            if (ModelState.IsValid)
            {
                DONOR entity = new DONOR(); 

                #region Insert Entities
                entity.Address = be.Address;
                entity.BarCode = be.BarCode;
                entity.BloodGroupId = be.BloodGroupId;
                entity.CityId = be.CityId;
                entity.CNIC = be.CNIC;
                entity.DOB = be.DOB;
                entity.Email = be.Email;
                entity.EmergencyContact = be.EmergencyContact;
                entity.FullName = be.FullName;
                entity.GenderId = be.GenderId;
                entity.HomeNo = be.HomeNo;
                entity.IsActive = true;
                entity.IsDeleted = false;
                entity.LastDonDate = be.LastDonDate;
                entity.MaritalStatus = be.MaritalStatus;
                entity.MobileNo = be.MobileNo;
                entity.Occupation = be.Occupation;
                entity.PreDonCount = be.PreDonCount;
                if (be.RegCampId != 0) { entity.RegCampId = be.RegCampId; entity.RegistrationTypeId = 3; }
                if (be.RegLocId != 0) { entity.RegLocId = be.RegLocId; entity.RegistrationTypeId = 2; }
                entity.SignPic = entity.SignPic;
                entity.WhatsApp = be.WhatsApp;
                entity.CreatedBy = (int)HttpContext.Session.GetInt32("UserId");
                entity.CreatedDateTime = DateTime.Now;

                #endregion
                flag = await _donorContext.AddAsync(entity);

                if (pic == null || pic.Length <= 0)
                    be.Pic = Path.Combine(_hostingEnvironment.WebRootPath, "images", "Avatar.png").Replace(_hostingEnvironment.WebRootPath, "").Replace("\\", "/");

                if (pic != null && pic.Length > 0)
                {
                    var path = Path.Combine(new string[]
                    {
                            _hostingEnvironment.WebRootPath,
                            "Reservoir","Donor",entity.Id.ToString(),
                            entity.Id + Path.GetExtension(pic.FileName)
                    });
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                    using (var stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                    {
                        pic.CopyTo(stream);
                    }
                    path = path.Replace(_hostingEnvironment.WebRootPath, "").Replace("\\", "/");
                    entity.Pic = path;

                    entity.CreatedBy = entity.CreatedBy;
                    entity.CreatedDateTime = entity.CreatedDateTime;
                    entity.IsActive = true;
                    entity.IsDeleted = false;
                    await _donorContext.UpdateAsync(entity);
                }

                if (flag)
                {
                    TempData["Message"] = "Donor is Added Successfully.";
                    if (be.RegCampId != 0)
                    {
                        return RedirectToAction("Create", "Donor", new { CampId = be.RegCampId });
                    }
                    else
                    {
                        return RedirectToAction("Create", "Donor");
                    }
                }
            }
            ViewData["RegCampId"] = new SelectList(_context.BLOOD_CAMP, "Id", "City", be.RegCampId);
            ViewData["BloodGroupId"] = new SelectList(_bloodGroupContext.GetAll(), "Id", "Value", be.BloodGroupId);
            ViewData["CityId"] = new SelectList(_cityContext.GetAll(), "Id", "Name", be.CityId);
            ViewData["ScreenedBy"] = new SelectList(_context.EMPLOYEE, "Id", "FirstName", be.ScreenedBy);
            ViewData["GenderId"] = new SelectList(_genderContext.GetAll(), "Id", "Name", be.GenderId);
            ViewData["RegLocId"] = new SelectList(_locationService.GetAll(), "Id", "Name",be.RegLocId);

            return View(be);
        }


This is My Create method In Controller How to unit test it using UnitTest.

using HMS_Presentation.Controllers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;


//Unit Test code .

namespace HMS_UnitTest
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {

            DonorController Controller = new DonorController();

            ViewResult result = Controller.Create() as ViewResult;

            Assert.AreEqual("",????);


        }
    }
}

它表示网站在url之间的转换,引荐是指从第1页转到第2页的可能性。我需要获取一个转换矩阵。所以我需要的输出是这样的:

[{'url1':[{'url11': [{'label':'url111', 'referrals': 0.1},{'label':'url112', 'referrals':0.4}] , 'referrals' :0.2}, {'url12': [{'label':'url121', 'referrals': 0.1}, {'label':'url122', 'referrals':0.4}], 'referrals':0.5}] },
{'url2' :[{'url21': [{'label':'url211', 'referrals': 0.1}, {'label':'url212', 'referrals':0.4}] , 'referrals' :0.2}, {'url22': [{'label':'url221', 'referrals': 0.2}, {'label':'url222', 'referrals':0.2}], 'referrals':0.3}]}]

实际上,当用户在页面之间浏览时,可能会返回上一页,因此 url1 url11 url111 url112 ... url12...... url222 url1 0 0.2 NA NA 0.2 url11 .. url111 . . . . . 可能是url111,所以这不是问题,我可以处理这些复制之后。

0 个答案:

没有答案