i would like to visualize what i will get after concatenation of map and struct in matlab , for instance let us consider following Map Container
ticketMap = containers.Map(...
{'2R175', 'B7398', 'A479GY', 'NZ1452'}, ...
{'James Enright', 'Carl Haynes', 'Sarah Latham', ...
'Bradley Reid'});
key/value structure of this map is clear for me, now let us suppose we have following structure
s1.ticketNum = '2S185'; s1.destination = 'Barbados';
s1.reserved = '06-May-2008'; s1.origin = 'La Guardia';
s2.ticketNum = '947F4'; s2.destination = 'St. John';
s2.reserved = '14-Apr-2008'; s2.origin = 'Oakland';
s3.ticketNum = 'A479GY'; s3.destination = 'St. Lucia';
s3.reserved = '28-Mar-2008'; s3.origin = 'JFK';
s4.ticketNum = 'B7398'; s4.destination = 'Granada';
s4.reserved = '30-Apr-2008'; s4.origin = 'JFK';
s5.ticketNum = 'NZ1452'; s5.destination = 'Aruba';
s5.reserved = '01-May-2008'; s5.origin = 'Denver';
we have 5 structure with different fields, now following commands
seatingMap = containers.Map( ...
{'23F', '15C', '15B', '09C', '12D'}, ...
{s5, s1, s3, s4, s2});
make sense for me because for instance using key 23F i can access fields of s1 structure, for instance
>> seatingMap('23F').origin
ans =
'Denver'
all those parts are clear for me, now Using ticketMap and seatingMap together, you can find the name of the person who has reserved seat 15B
ticket = seatingMap('15B').ticketNum;
passenger = ticketMap(ticket)
but is that optimal way?thanks in advance
Related
I have a string that looks like this
start
"contrib_11_FICO_Score = 0.7474262402579245 contrib_27_OtherPayments = -0.11397237107501418 contrib_20_LTV = 0.4209136780360599 contrib_0_AcctsOnUs = -0.195553721371136 contrib_19_InstallmentPayments = 0.08134999563389797 contrib_1_Amount = 0.07752028501333455 contrib_10_EstDebtToIncome = 0.19793275869285348 contrib_45_CVTE_ProductShortName.0 = 0.08545325753810393 contrib_21_LoanTerm = -0.20186524569828262 contrib_43_SatisfactoryLast2Yrs = 0.0710695727171011 contrib_50_WoE_ProductShortName.0 = -0.022073850549082376 contrib_31_PLCollectionTotal = 0.12617956675796796 contrib_40_RevBalToHighCredit = -0.5009070556076041 contrib_42_RevolvingPayments = 0.14787007118011708 contrib_39_RepoTotal = 0.002261663457841503 contrib_30_PLCollectionLast2yrs = 0.047241412208721086 contrib_15_InquiriesOnUs = -0.08118475273646548 contrib_17_InquiriesTotal = -0.23934745152247694 contrib_16_InquiriesToday = 0.06067597032236759 contrib_23_OilTE = -0.009115867521724635 contrib_14_InquiriesLast6mos = -0.01669536361883669 contrib_8_DTI = 0.40070958319864824 contrib_44_SatisfactoryTotal = -0.29471031930209096 contrib_22_Mortgage = -0.13973120155639737 contrib_3_AvgRevolvingBalance = -0.1339820646758586 contrib_41_RevolvingCount = 0.008316986809544236 contrib_32_Plus30Last2Yrs = 0.0315266336181764 contrib_29_OtherPublicTotal = 0.0025079738312499887 contrib_12_Inquiries30days = 0.08842218013671509 contrib_36_Plus90Last2Yrs = 0.03415210455083352 contrib_6_BankruptcyLast2yrs = 0.0037646391378712307 contrib_34_Plus60Last2Yrs = 0.014917255339436795 contrib_28_OtherPublicLast2yrs = 9.508765288605479E-4 contrib_bias = 0.7414680413223248"
and I'm trying to coerce it to a hash, like this.
end
{"contrib_11_FICO_Score"=>0.7474262402579245, "contrib_27_OtherPayments"=>-0.11397237107501418, "contrib_20_LTV"=>0.4209136780360599, "contrib_0_AcctsOnUs"=>-0.195553721371136, "contrib_19_InstallmentPayments"=>0.08134999563389797, "contrib_1_Amount"=>0.07752028501333455, "contrib_10_EstDebtToIncome"=>0.19793275869285348, "contrib_45_CVTE_ProductShortName"=>0.08545325753810393, "contrib_21_LoanTerm"=>-0.20186524569828262, "contrib_43_SatisfactoryLast2Yrs"=>0.0710695727171011, "contrib_50_WoE_ProductShortName"=>-0.022073850549082376, "contrib_31_PLCollectionTotal"=>0.12617956675796796, "contrib_40_RevBalToHighCredit"=>-0.5009070556076041, "contrib_42_RevolvingPayments"=>0.14787007118011708, "contrib_39_RepoTotal"=>0.002261663457841503, "contrib_30_PLCollectionLast2yrs"=>0.047241412208721086, "contrib_15_InquiriesOnUs"=>-0.08118475273646548, "contrib_17_InquiriesTotal"=>-0.23934745152247694, "contrib_16_InquiriesToday"=>0.06067597032236759, "contrib_23_OilTE"=>-0.009115867521724635, "contrib_14_InquiriesLast6mos"=>-0.01669536361883669, "contrib_8_DTI"=>0.40070958319864824, "contrib_44_SatisfactoryTotal"=>-0.29471031930209096, "contrib_22_Mortgage"=>-0.13973120155639737, "contrib_3_AvgRevolvingBalance"=>-0.1339820646758586, "contrib_41_RevolvingCount"=>0.008316986809544236, "contrib_32_Plus30Last2Yrs"=>0.0315266336181764, "contrib_29_OtherPublicTotal"=>0.0025079738312499887, "contrib_12_Inquiries30days"=>0.08842218013671509, "contrib_36_Plus90Last2Yrs"=>0.03415210455083352, "contrib_6_BankruptcyLast2yrs"=>0.0037646391378712307, "contrib_34_Plus60Last2Yrs"=>0.014917255339436795, "contrib_28_OtherPublicLast2yrs"=>9.508765288605479E-4, "contrib_bias"=>0.7414680413223248}
I can use gsub(" = ","=>")
.gsub(" contrib",","contrib").gsub("\","")
but I end up with
\"contrib
The backslashes prevent me from converting this to a hash. How can I strip the backslashes out? I would have thought that the escape character would work, but apparently not.
I also tried splitting the string on the space, but this gave me an array of strings and not a hash.
Thanks for any suggestions!
I am using Core data to store two databases that contain a relationships.
There is a logbook database and a IFRApproaches database.
A logbook entry can have multiple approaches.
An approach can only be linked to one logbook entry.
Attached is screenshots of my data model and relationships.
When the "submit" button is pressed this is the code to save the entry to the logbook, and the approaches as well.. I need the approaches (how ever many) associated with a singular entry. My question is How I can use a predicate to query the database at a later time for all the approaches associated with a various entry.
lazy var newEntry = Logbook(context: LoadData.shared.context)
if errorCount == 0 {
if modifyEntry == false {
if entryHolding.date == nil {
newEntry.date = Date()
} else {
newEntry.date = entryHolding.date
}
newEntry.aircraftID = entryHolding.aircraftID
newEntry.aircraftSelect = LoadData.shared.aircraftArray[aircraftArrayIndexPath!.row]
newEntry.categoryAndClass = newEntry.aircraftSelect?.categoryAndClass
newEntry.typeCode = entryHolding.typeCode
newEntry.from = entryHolding.from
newEntry.to = entryHolding.to
newEntry.route = entryHolding.route
newEntry.totalTime = entryHolding.totalTime
newEntry.pic = entryHolding.PIC
newEntry.sic = entryHolding.SIC
newEntry.solo = entryHolding.solo
newEntry.dual = entryHolding.dual
newEntry.crossCountry = entryHolding.crossCountry
newEntry.night = entryHolding.night
newEntry.simInstrument = entryHolding.simInstrument
newEntry.actualInstrument = entryHolding.actualInstrument
newEntry.hold = Int16(entryHolding.hold)
newEntry.dayLanding = Int16(entryHolding.dayLanding)
newEntry.nightLanding = Int16(entryHolding.nightLanding)
newEntry.bfr = entryHolding.BFR
newEntry.checkride = entryHolding.checkRide
newEntry.ipc = entryHolding.IPC
newEntry.comments = entryHolding.comments
for i in 0..<approach.count {
var newApproach = IFRApproaches(context: LoadData.shared.context)
newApproach.airport = approach[i].airportID
newApproach.typeOfApproach = approach[i].type
newApproach.runway = approach[i].runwayNum
//newApproach.entry = newEntry
newEntry.addToApproaches(newApproach)
LoadData.shared.approachArray.append(newApproach)
}
LoadData.shared.entryArray.append(newEntry)
LoadData.shared.saveData()
I have a Profile model and Complain model both are connected to the inbuilt User model.I have to do a query using both in which Profile model have residence. I want to have a count, that how many complains are made from a particular residence. I can do it using SQL but I didn't know how to do it using Django.
SELECT users_profile.residence,count(user_id)from users_profile INNER JOIN chp_complain on(users_profile.user_id = chp_complain.complain_user_id)GROUP BY(user_id)
Complain Model:-
class Complain(models.Model):
complain_user = models.ForeignKey(User, on_delete=models.CASCADE)
complain_department=models.CharField(max_length=100)
complain_subject = models.CharField(max_length = 100,help_text = "Enter the complain subject")
department_head=models.CharField(max_length=100)
recepient=models.CharField(max_length=100)
complain_description=models.TextField(max_length=2000)
date_posted = models.DateTimeField(default = timezone.now)
NOT_VISITED = 'NV'
VISITED = 'V'
INPROCESS = 'IP'
COMPLETED = 'C'
status = (
(NOT_VISITED, 'NV'),
(VISITED, 'V'),
(INPROCESS, 'IP'),
(COMPLETED, 'C'),)
status=models.CharField(max_length=2,choices=status,)
Profile Model:-
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
UID =models.CharField(max_length=30,default = "000",help_text = "'Staff's fill their STAFF ID and student's fill their ROLL NO " )
MALE = 'M'
FEMALE = 'F'
Gender=((MALE, 'Male'),(FEMALE, 'Female'),)
Gender=models.CharField(max_length=6,choices=Gender,default=MALE,)
FIRST = '1st'
SECOND = '2nd'
THIRD = '3rd'
FOURTH = '4th'
NGH = 'NGH'
NON_HOSTELER = 'Non_hosteler'
TEACHER_QUARTER = 'Teacher_quarter'
residence = ((FIRST, 'First'),(SECOND, 'Second'),(THIRD, 'Third'),(FOURTH, 'Fourth'),(NGH,'NGH'),(NON_HOSTELER, 'Non_hosteler'),(TEACHER_QUARTER,'Teacher_quarter'))
residence = models.CharField(max_length=20,choices=residence,default=FIRST,)
room_no=models.CharField(max_length=10,default = "000")
I want to have a count, that how many complains are made from a particular residence you can write:
Complain.objects.values('complain_user__profile__residence').annotate(complains_count=Count('id'))
In your SQL query:
SELECT users_profile.residence,count(user_id)from users_profile INNER JOIN chp_complain on(users_profile.user_id = chp_complain.complain_user_id)GROUP BY(user_id)
You calculate how many users filed complaints from a particular residence. It can be calculated as follows:
User.objects.values('profile__residence').annotate(Count('id'))
I have similar to the link below problem.
EPPlus chart from list of single excel cells. How?
I tried the code but it shows it twice in the chart. For example:
This code show excel chart -> select data-> horizontal(category) axis labels tab you show 100,100,300,600 write. What is the reason for this? The chart is written twice the first data I did not find a solution to the problem.
I think you just discovered a bug with EPPlus. Shame on me for not noticing that with that post you reference. It seems that when using the Excel union range selector (the cell names separated by commas) the iterator for the ExcelRange class returns a double reference to the first cell, in this case B2.
A work around would be to use the other overload for Series.Add which will take two string ranges. Here is a unit test that show the problem and the workaround:
[TestMethod]
public void Chart_From_Cell_Union_Selector_Bug_Test()
{
var existingFile = new FileInfo(#"c:\temp\Chart_From_Cell_Union_Selector_Bug_Test.xlsx");
if (existingFile.Exists)
existingFile.Delete();
using (var pck = new ExcelPackage(existingFile))
{
var myWorkSheet = pck.Workbook.Worksheets.Add("Content");
var ExcelWorksheet = pck.Workbook.Worksheets.Add("Chart");
//Some data
myWorkSheet.Cells["A1"].Value = "A";
myWorkSheet.Cells["A2"].Value = 100; myWorkSheet.Cells["A3"].Value = 400; myWorkSheet.Cells["A4"].Value = 200; myWorkSheet.Cells["A5"].Value = 300; myWorkSheet.Cells["A6"].Value = 600; myWorkSheet.Cells["A7"].Value = 500;
myWorkSheet.Cells["B1"].Value = "B";
myWorkSheet.Cells["B2"].Value = 300; myWorkSheet.Cells["B3"].Value = 200; myWorkSheet.Cells["B4"].Value = 1000; myWorkSheet.Cells["B5"].Value = 600; myWorkSheet.Cells["B6"].Value = 500; myWorkSheet.Cells["B7"].Value = 200;
//Pie chart shows with EXTRA B2 entry due to problem with ExcelRange Enumerator
ExcelRange values = myWorkSheet.Cells["B2,B4,B6"]; //when the iterator is evaluated it will return the first cell twice: "B2,B2,B4,B6"
ExcelRange xvalues = myWorkSheet.Cells["A2,A4,A6"]; //when the iterator is evaluated it will return the first cell twice: "A2,A2,A4,A6"
var chartBug = ExcelWorksheet.Drawings.AddChart("Chart BAD", eChartType.Pie);
chartBug.Series.Add(values, xvalues);
chartBug.Title.Text = "Using ExcelRange";
//Pie chart shows correctly when using string addresses and avoiding ExcelRange
var chartGood = ExcelWorksheet.Drawings.AddChart("Chart GOOD", eChartType.Pie);
chartGood.SetPosition(10, 0, 0, 0);
chartGood.Series.Add("Content!B2,Content!B4,Content!B6", "Content!A2,Content!A4,Content!A6");
chartGood.Title.Text = "Using String References";
pck.Save();
}
}
Here is the output:
I will post it as an issue on their codeplex page to see if they can get it fixed for the next release.
How can I optimize all of these routes into one. As we do in .htaccess file.
routes.addemails.type = "Zend_Controller_Router_Route_Regex"
routes.addemails.route = "campaign/email/add"
routes.addemails.defaults.module = campaignManagement
routes.addemails.defaults.controller = Email
routes.addemails.defaults.action = add
routes.updateEmail.type = "Zend_Controller_Router_Route_Regex"
routes.updateEmail.route = "campaign/email/edit/?([a-zA-Z0-9_-]+)?"
routes.updateEmail.defaults.module = campaignManagement
routes.updateEmail.defaults.controller = Email
routes.updateEmail.defaults.action = edit
routes.updateEmail.map.key = 1
routes.delEmail.type = "Zend_Controller_Router_Route_Regex"
routes.delEmail.route = "campaign/email/delete/?([a-zA-Z0-9_-]+)?"
routes.delEmail.defaults.module = campaignManagement
routes.delEmail.defaults.controller = Email
routes.delEmail.defaults.action = delete
routes.delEmail.map.id = 1
I've not set up a route using a config file, but at a glance try:
routes.emails.route = "campaign/email/(add|edit|delete)/?([a-zA-Z0-9_-]+)?"
routes.emails.map.action = 1
routes.emails.map.id = 2
I am assuming that the map.* are the variables in the url (so action is the first bit of regex, with id being the second bit of regex. Correct me if I'm wrong).