How to model state change timeline I've got an app where users can place orders for recurring delivery of a particular service.  The orders table has columns service_id and state, where service_id links to the service the user has ordered and state can be active or inactive, reflecting whether the user currently wants to receive that service or not. Users can toggle orders on and off as they please.  When a user turns an order on or off (active/inactive) I need to track this, and I need to be able to query for whether an order was active or inactive on a given date.  My question is: What's the best way to to model something like this, specifically so that I can easily write a query like "all orders that were active on (date)"?  I've thought about making a orders_states table with order_id, state, and date, where each change create a row with the state that was set and the date it was set, but I'm not 100% sure about how I'd query it to get the past state on an arbitrary date, or if there's a better way to model this.  I'm testing / prototyping on this now, but I'm obviously not a SQL expert and would love some suggestions from the pros here. Thanks!  (I'm using Postgres 9.4.1.2 in case that matters, but I figure this is more of a generic SQL modeling question)
How to get status start_date and end_date from status_track table? I have two tables:   things:  +------+----------------+------------+ | id   | current_status | created_at | +------+----------------+------------+ | 7770 | active         | 2016-08-09 | +------+----------------+------------+  thing_status_tract:  +----------+-------------+-----------+---------------------+ | thing_id | status_from | status_to | changed_at          | +----------+-------------+-----------+---------------------+ |     7770 | incomplete  | inactive  | 2016-08-09 16:26:22 | |     7770 | inactive    | active    | 2016-08-10 12:31:04 | +----------+-------------+-----------+---------------------+    I need data in the following form. This table has a status and its corresponding start and end timestamp for a particular thing_id:  +----------+-------------+---------------------+---------------------+ | thing_id | status      | status_start_date   | status_end_date     | +----------+-------------+---------------------+---------------------+ |     7770 | incomplete  | 2016-08-09 00:00:00 | 2016-08-09 16:26:22 | |     7770 | inactive    | 2016-08-09 16:26:22 | 2016-08-10 12:31:04 | |     7770 | active      | 2016-08-10 12:31:04 | now()               | +----------+-------------+---------------------+---------------------+   How to do that with a SQL query?
We will generate a csv file with below values  yp1234,577,1,3 yp5678,577,3,5 yp9012,132,8,9   I need to extract data and create files based on second column. If it's 577 then the whole line has to be extracted and placed in a separate file. I mean I need a file having lines with second column as 577 alone and another file with second column as 132 alone  I tried using IF but didn't work Other ways to say "I have a bad hunch" I'm looking for ways to say "I'm having a bad hunch", or more like a bad feeling about something upcoming. The gut-wrenching feeling that something bad will happen. How are the measurements used by Nielsen evolving to meet new methods of content delivery and viewing? I was interested to find out that in the 1950s, Nielsen used devices in the homes of the families that were surveyed to record their viewing preferences, and only later introduced their system of using a diary to record habits:  ...in 1950...This information was collected on a device that was attached to a television that recorded what was being watched.  In 1953, the company began sending out diaries to a smaller sample of homes (“Nielsen families”) within the survey to have them record what they had watched from   So, presumably as multiple different viewers in the home were considered in the sample, the means through which the ratings were recorded changed. Given that so many people are able to record shows digitally and watch when convenient and that so many view their favorites on outlets such as iTunes, how have the Nielsen ratings systems adapted (or how does the company plan to adapt them) to capture our modern viewing preferences? While a DVR-recorded show still technically makes its original &quot;timeslot&quot; relevant to the equation, will Nielsen consider timeslot-specific data a hindrance to comparisons between those shows viewed on cable and the same show viewed on iTunes? Using launchd to update MacPorts I want to use launchd to update my MacPorts tree periodically (i.e. port selfupdate.  I have created /Library/LaunchDaemons/org.macports.selfupdate.plist:   $ ls -l /Library/LaunchDaemons/org.macports.selfupdate.plist -rw-r--r--  1 root  wheel  669  8 Nov 12:49 /Library/LaunchDaemons/org.macports.selfupdate.plist   It has the following contents:   &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;org.macports.selfupdate&lt;/string&gt; &lt;key&gt;ProgramArguments&lt;/key&gt; &lt;array&gt;     &lt;string&gt;/opt/local/bin/port&lt;/string&gt;     &lt;string&gt;selfupdate&lt;/string&gt; &lt;/array&gt; &lt;key&gt;StandardOutPath&lt;/key&gt; &lt;string&gt;/var/log/org.macports.selfupdate.log&lt;/string&gt; &lt;key&gt;StandardErrorPath&lt;/key&gt; &lt;string&gt;/var/log/org.macports.selfupdate.err&lt;/string&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;key&gt;StartInterval&lt;/key&gt; &lt;integer&gt;604800&lt;/integer&gt;&lt;!-- 1 week --&gt; &lt;/dict&gt; &lt;/plist&gt;   I've loaded it and verified that it's loaded:  $ launchctl list | grep macports -   78  org.macports.selfupdate   But it doesn't look like it actually run.    $ port info wireshark Warning: port definitions are more than two weeks old, consider updating them by running 'port selfupdate'. wireshark @1.12.8_3 (net) ...   What am I missing? Conditional Expectaction 3 variables Suppose $X,Y$ and $Z$ are multivariate normal with means and full covariance matrix. The conditional expectation $E(X | Y)$ is well know. What is the conditional expectation of $E(X | Y,Z)$ if $Y$ and $Z$ (and $X$) are correlated? Standard textbooks only seem to cover the case when $Y$ and $Z$ are uncorrelated. I could install with an error message "unknown media /ALL". It could not run WPS Office. A question about using the "v-ing" verbs To native speakers, normally do you use adverbs to modify these v-ing worlds especially when they are the objects of the verbs?  Like:      I regret swimming hurriedly     Not      I regret hurried swimming.      Right? And what about these two sentences:     I regret stamp-collecting     or     I regret collecting stamps   Besides, when using these words, it still retains the verbal characteristics right? Like:       The house needs a careful cleaning.     has the same meaning with       The house needs carefully cleaning.     or       The house needs to be cleaned carefully.   (SOMETHING like passive voice) The highest common factor and the lowest common multiple of two numbers $A$ and $B$ are $12$ and $168$ respectively. Find the possible values of $A$ and $B$ with the exception of $12$ and $168$.   Help me with this equation please. I kind of get it but I don't understand the concept behind it... I do not want to memorize. If the big bang was the birth of everything, and the big bang was an event in the sense that it had a location and a time (time 0), wouldn't that mean that our universe has a center?  Where was the big bang? What is there now? Are we moving away from the center still? Are these even valid questions? Time Manager (QGIS) date format I've been through associated answers but cannot quite seem to find something which works!  I'm having trouble getting TimeManager to recognise a simple data field (this is in QGIS2 - but I've had this error in earlier versions). I have these fields formatted in what appears to be one of the acceptable formats:    ... here is a screenshot of the field properties:    The format appears to be recognised in QGIS as I've worked out days difference between two dates (the "Time on Market" field shown in the image).  However ... I always end up with:   The Twitter.shp file works fine as a test, so I don't think this is an issue with the install / phyton conflict.  Any thoughts welcome! Double rm verification in zsh When I do a rm * in zsh, I get something like this:  2014-06-08 10:14:23 $ rm * zsh: sure you want to delete all the files in /home/assay/assay/log [yn]? y rm: remove regular file `development.log'? y   First zsh asks me if I am sure I want to delete all, and then rm asks for for each specific file.  How can I just have the zsh verification? Is there evidence of dark matter in our galaxy? Is there evidence of dark matter in our galaxy?  How can we measure this, say, how many percent of the center of our galaxy is dark matter?  I did not find the answer in the question Do the search engines take the number of 404 errors returned by a site into account when calculating the site rank? For example I have 8,000 404 errors and I am thinking that that's affecting my SEO in a negative way.  However, I read  about 404 errors which suggests that they are not always a negative quality indicator.   So I am confused...are high numbers of 404 errors harmful to a site or not? Laplace transform of integral constant I am trying to perform a multiple regression in R. However, my dependent variable has the following plot:    Here is a scatterplot matrix with all my variables (WAR is the dependent variable):    I know that I need to perform a transformation on this variable (and possibly the independent variables?) but I am not sure of the exact transformation required. Can someone point me in the right direction? I am happy to provide any additional information about the relationship between the independent and dependent variables.  The diagnostic graphics from my regression look as follows:    EDIT  After transforming the dependent and independent variables using Yeo-Johnson transformations, the diagnostic plots look like this:    If I use a GLM with a log-link, the diagnostic graphics are: How can I subdivide this plane into even squares? Who should I be damage buffing as Mercy I just started playing Overwatch (played a few games during open beta, but wasn't able to play much). I'm enjoying Mercy, but who (in a group situation) should be getting the damage buff? Additionally, when my team splits up, who should I follow to support? I wish to print a Stack&lt;Integer&gt; object as nicely as the Eclipse debugger does (i.e. [1,2,3...]) but printing it with out = "output:" + stack doesn't return this nice result.  Just to clarify, I'm talking about Java's built-in collection so I can't override its toString().  How can I get a nice printable version of the stack? Let $(X, d(x,y))$ be a complete metric space. Prove that if $A\subseteq X$ is a closed set, then $A$ is also complete.  My attempt: I tried to prove that every Cauchy sequence $(b_n)$ of points of $A$ converges to a point $b\in A$. However could not figure out the exit way. Maybe I am on the wrong track. Could you please help me?  edit: More from my attempt:  Suppose $A$ is a closed set and let $(x_n)$ be a sequence of points $A$ such that $\lim_n x_n\to b$.  Suppose now that $A$ has the property that $b\in A$, whenever $x_n$ converges to $b$. We know that every element of $x_n$ which is convergent in $X$ also converges to a point in $A$. Since $x_n$ is a Cauchy sequence in $A$, it must converge to a point $y\in A$. But the limit of a convergent sequence is unique.   Take $x\in A$ and select an appropriate $n$, which enables $x_n$ to converge to a point $x$ in $X$. Since the limit is unique, it must follow that $x=y$. Thus $x\in A$ and $A$ is closed.   If $A$ is a closed subset of $X$, then any Cauchy sequence of a point in $A$ is convergent in $X$ and hence converges to a point in $A$. Thus $A$ is complete. The following code is generating a stack overflow error for me  int main(int argc, char* argv[]) {     int sieve[2000000];     return 0; }   How do I get around this? I am using Turbo C++ but would like to keep my code in C  EDIT:  Thanks for the advice.  The code above was only for example, I actually declare the array in a function and not in sub main.  Also, I needed the array to be initialized to zeros, so when I googled malloc, I discovered that calloc was perfect for my purposes.  Malloc/calloc also has the advantage over allocating on the stack of allowing me to declare the size using a variable.