Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I want to read orders from order.txt which is;
Chocolate Chip Cookies 1 2
Orange Jelly Candy 2 7
Chocolate ice cream 3 11
Cake Mix Cookies 1 10
And decide if there is enough product from stock.txt which is;
Name Type ItemCount Price
Chocolate Chip Cookies 1 4 600
Orange Jelly Candy 2 5 150
Cake Mix Cookies 1 12 180
Peanut Butter Chocolate Chip Cookies 1 3 120
Chocolate ice cream 3 2 240
Gummi bears 2 15 300
Raspberry Ripple 3 12 250
Alignment is given like that. What is the best way to do it? Is there anything to read from a file which I can store in a way like product name/ number/ price?
Thank you.
I don't understand what the second and third column signify, I assume one of them is order size.
There are many ways to do this and my method might not be the best in all cases but at least it should work in yours:
Read the stock.txt file, you can look at this example but it doesn't really matter what method you use. The important thing is to get the information as a variable into the program. Hopefully your text files uses a tab to separate the fields (this information is lost in the question).
Put the information you get into a std::map, call it orders, use the name as key and the ItemCount as value.
Now read the information in order.txt, use the key to look up the value in your orders.
Check that ItemCount is at least a large as the order size.
In a real world application you would use a Database to store the data of your stock and would write a class order which gets its values from the databas. However i dont think you want to have that much effort so here's a esier way:
Your stock data gets saved in a simple excel table and the order is a textfile
Order.txt:
Beer 1|Paint 5|Oil 3|.....
Use the | as markers to create substrings of the individual products in the order
Bsp. ProductName quantity id|ProductName2 quantity id2|....
As for the excel table you have to to a little research yourself but editing files with a filereader isn't that hard though.
Hope i can help
Related
I'm trying to have information about the completeness in some survey results exported in to a Excel Format. I'm using Google Sheets, as every survey there is questions and subquestions the subquestions have a conditional, Example: 4. How are you today? multiple choice answers: Good, Bad, Prefer not to say, so there we have 3 answer options if we click good there is a conditional and the subquestion will be: Why?.
So in my survey there is 8 questions and question 4, 7 and 8 has conditional questions if someone answer "Yes".
Now here is my problem: to calculate the percentage of completeness I used this relation --> number of inputs in the survey/number of expected answers.
But as I mentioned before the conditional affects this expected answers this Variable is dynamic depending on the answers from question 4, 7 and 8. So I would like to obtain this Variable for every case, if someone put information will have an ID if we have 20 persons doing the survey we will have 20 ID's.
So for every record of answers the number will change depending on the inputs from Question 4, 7 and 8. I have prepared a document in Google sheets will the full approach that I tried but is still hard to have it right I would like to have some help with this.
I would like to use this kind of formula:
=COUNTIF(AI2:AR2,"Yes")>0
This tell me if in the range of the Question 4 there is a "Yes" to activate the subquestions.
Then : `IF(TRUE, 11, 1) Which should be the count if in Q4 there is a Yes at least for that row. That's a little simpler but is the approach I would like to do.
This is the points:
if any of these parts are filled with YES or NO that's 1 point for whole Q4(Correct)
every part of SUBquestion count as 1 (Correct)
if SUBquestion is filled does MAINquestion count as the sum of MAIN QUESTION and number of SubQuestions. Case of Q4: Answer was Yes, the count will be 11 the 10 parts plus the Main one. If Answer was No the count will be 1.
Link to Spreadsheet
In the file you will find more information.
Please some help with this I'm having days trying to solve it
Here is an image about it:
If I understood your question correctly this is the approach you want.
Try the following:
For Q4: =IF(COUNTIF('Original Data Base'!AI2:AR2,"Yes")>0,11,1)
For Q7: =IF(COUNTIF('Original Data Base'!BF2,"Yes")>0,2,1)
For Q8: =IF(COUNTIF('Original Data Base'!BI2:BR2,"Yes")>0,11,1)
Drag down to rows below.
Then to get the percentage of completeness use:
=(SUM('Anwers formula'!B2:AD2)/SUM(C2:J2))*100
To explain this syntax -> This gets the (Answer count / Number of expected answers) X 100 to get the percentage.
Result:
This returns the same result as you have in your sample sheet "Last Step".
Or all together in one formula:
=(SUM('Anwers formula'!B2:AD2)/SUM(5+(IF(COUNTIF('Original Data Base'!AI2:AR2,"Yes")>0,11,1))+(IF(COUNTIF('Original Data Base'!BF2,"Yes")>0,2,1))+(IF(COUNTIF('Original Data Base'!BI2:BR2,"Yes")>0,11,1)))*100)
You can remove the * 100 and format it to percent value.
Let me know if this resolves your concern, or if you need help adjusting this to your spreadsheet.
I have a survey data with 5 Question
1.) Whom yu are living with : girlfriend, wife
2.) If the person healthy : yes, no, partially
3.) Is the person working : Yes, No
4.) Are you happy with the person : Yes, No, Cant Say
5.) If the person owns a house : yes, no
I want to analyse one answer impacts the rest of the answers. For eg. how many of perople living with wife who has house and are happy. The requirement is to analyse these answers along each other.
The data collected is this format below. Please suggest what would be the best way to analyse the data in such fashion.
UserId Question Answer
1 Whom yu are living with Wife
1 If the person healthy Yes
1 Is the person working No
1 Are you happy with the person Yes
1 If the person owns a house No
2 Whom yu are living with Girlfriend
2 If the person healthy Partial
2 Is the person working Yes
2 Are you happy with the person Yes
2 If the person owns a house No
3 Whom yu are living with Wife
3 If the person healthy Yes
3 Is the person working yes
3 Are you happy with the person No
3 If the person owns a house Yes
I initially thought of to create a tree map with Questions and Answers and use drill through the open second page with tree map filtered on the user id. But later i realized that the drill through could use the filters which are not part of the parent chart.
Than i thought of using parameters like SSRS, but power bi has limitation to have only one value to the parameters.
What i am looking for is a descent way to analyse this data. Or a workaround on the two possible options i tried to remove roadblocks.
I am open to any different way to analyse the data then i am doing if it answers the questions.
Maybe a simple one, but as long as you are not planning on doing statistical analysis and just want to explore the data, maybe create 5 bar charts with the category of the X and a count on the Y and use the build in interactions by clicking on different categories to gain a basic understanding.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm practicing with classes and I'm given the task of creating employee management system. I'm given two .txt files. One (details.txt) has details of each employee with the following info: ID, name, DOB, SSN, department, and position. A sample of the file looks like such:
5 ali 6/24/1988 126-42-6989 support assistant
13 tim 2/10/1981 131-12-1034 logistics manager
The other .txt (timelog.txt) will contain a daily log of when employees clock in and clock out. The following format for this file is: ID, date, clock in time, and clock out time. Sample:
5 3/11 0800 1800
13 3/11 0830 1830
Firstly, I am to allow users to search up an employee by ID, name, department or position. Doing so will display all of the employees info (multiple employees if they have the same name, position or are from the same department) as well as show the total number of hours they have worked in the company.
Secondly, users are to be given another option to look up employee time logs by ID number. This will display the entire clock in/ clock out history of that employee as well as total hours worked each day.
I'm planning to read in the info from .txt files via ifstream and store them as an array of objects. I'm just wondering how many classes I should create. I'm thinking 2 classes- one for employee info (from details.txt) and one for time logs(timelogs.txt). Is there any other class I should create or should those 2 suffice?
Short answer: At least two.
Long answer: It depends on many things. Especially what part of code you can identify as potentially reusable.
If you asked for the highest possible amount of classes that could accomplish your task, I would think about a single class for:
Employee
EmployeeManager (Factory, Holder etc.) – creates, holds and deletes the Employee objects, provides search feature
DayWork – a row from timelog.txt, can calculate the amount of hours/minutes spent in work that day
WorkLog – a list of DayWork objects for one employee, can calculate the whole spent time
TextLineParser – encapsulation of std::ifstream
The right answer is most likely somewhere between. Keep in mind that C++ is a multi-paradigm language and you can perform some operations without having a class for them. Instead, they can be performed in a function or a set of functions in a C-like unit. That’s especially useful for one-time operations where the functions don’t share common data (potential properties).
I am currently working with a large data set using R. So, I have a column called "Offers". This column contains text describing 'promotions' that companies offer on their products. I am trying to extract numeric values from these. While, for most cases, I am able to do so well using a combination of regex and functions in R packages, I am unable to deal with a couple of specific cases of text shown below. I would really appreciate any help on these.
"Buying this ensures Savings of $50. Online Credit worth 35$ is also available. So buy soon!"
1a. I want to get both the numeric values out but in 2 different columns. How
do I go about that?
1b. For another problem that I have to solve, I only need to take the value associated with the credit. It is always the case that for texts like above, the second numeric value in the text, if it exists, is the one associated with the credit.
"Get 50% off on your 3 night stay along with 25 credits, offer available on 3 December 2016"
(How should I only take the value associated with credits?)
Note: Efficiency would be important as well because I am dealing with about 14 million rows.
I have tried looking online for a solution but have not found anything very satisfactory.
I am not 100% sure about what you want but this may help you.
A <- "do 50% and whatever 23"
B <- gregexpr("\\d+",A)[[1]]
firstNum <- substr(A,B[1],B[1]+attr(B,"match.length")[1]-1)
secondNum <- substr(A,B[2],B[2]+attr(B,"match.length")[2]-1)
Hope this helps.
UPDATE:
I solved the first part of the problem. I created unique ids for each observation:
gen id=_n
Then, I used
fillin id categ
which essentially created what I was looking for.
However, for the rest of the variables (except id and categ), almost all observations are missing. Now, I need your help to duplicate the rest of the variables instead of having them missing.
Just as an example, each observation is associated with a particular week. I am missing most of them. Or another dummy variable indicates whether a purchase was made at a drug or grocery store. Most of them are missing too.
Thanks!
ORIGINAL MESSAGE:
Need your help in Stata!
Each observation in my database is a 1-unit purchase of a beer product made by a customer. These product purchases are categorized unto 8 general categories such that the variable "categ" has values from 1 to 8 (1=import, 2=craft, 3=premium, 4=light, etc).
For my multinomial logit model, I need to observe all categories purchased or not purchased by the customer in each observation.
Assume, this is my initial dataset:
customer id-------beer category-----units purchased
----------1------------------1--------------------- 1
----------2----------------- 3--------------------- 1
----------3 -----------------2 ---------------------1
This is what I am looking for:
customer id-------beer category-----units purchased
----------1------------------1--------------------- 1
----------1 -----------------2 ---------------------0
----------1----------------- 3--------------------- 0
----------2----------------- 1--------------------- 0
----------2----------------- 3--------------------- 1
----------2 -----------------3--------------------- 0
----------3----------------- 1--------------------- 0
----------3----------------- 2--------------------- 0
----------3 -----------------2 ---------------------1
Currently, my dataset is 600,000 obs. After this procedure, I should have 600,000*8=4,800,000 obs.
When constructing this code, it is necessary that all other variables in the dataset are duplicated according to the associated category of beer.
I assume that "fillin" and less likely "expand" might work.
You help will tremendously help.
Thanks!
This is an old question, but i'll post a possible answer if someone else is having this problem.
In this case, you could generate variables for every option of your "choice variable", and after that, apply the reshape long command:
tab beercategory, gen(b)
reshape long b , i(customerid) j(newvarname)
Greetings