|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
Damn i suck at SQL. Anyone that can help me out with this query?
In the table DimOperator, i want non duplicate values of the column OperatorKey. Included in the results i need the DateLoaded column and the ID column. The values in ID and DateLoaded have no possibility of being a duplicate so i need only to display them so i can cross reference with another database. The problem is that i need a count of the column OperatorKey without duplicate values. I have tried this in two steps, aka getting no duplicates at first and then working a count in there(i'm a newb)
Here's what i have tried so far:
select distinct OperatorKey, ID, DateLoaded from DimOperator order by DateLoaded desc - Does not return unique OperatorKey, returns several of the same value.
select MIN(OperatorKey) AS OperatorKey, DateLoaded from DimOperator group by OperatorKey, DateLoaded order by DateLoaded desc - Same problem as above, it does not return unique OperatorKey's. I have no real reasoning for trying these other then based on similar google examples.
This would be my failed attempts at the first step, however if someone can manage a count on the column OperatorKey that does not include duplicate values that'd be super as well. If there's an explanation to the query as well then i might just be in heaven... 
Results i get:
Operator Key DateLoaded ID 402 2013-xx 8052 402 2013-xx 8053 403 2013-xx 8054
Results i want: 402 2013-xx 8052 403 2013-xx 8054 etc
|
|
|
On March 20 2014 17:34 unkkz wrote:Damn i suck at SQL. Anyone that can help me out with this query? In the table DimOperator, i want non duplicate values of the column OperatorKey. Included in the results i need the DateLoaded column and the ID column. The values in ID and DateLoaded have no possibility of being a duplicate so i need only to display them so i can cross reference with another database. The problem is that i need a count of the column OperatorKey without duplicate values. I have tried this in two steps, aka getting no duplicates at first and then working a count in there(i'm a newb) Here's what i have tried so far: select distinct OperatorKey, ID, DateLoaded from DimOperator order by DateLoaded desc - Does not return unique OperatorKey, returns several of the same value. select MIN(OperatorKey) AS OperatorKey, DateLoaded from DimOperator group by OperatorKey, DateLoaded order by DateLoaded desc - Same problem as above, it does not return unique OperatorKey's. I have no real reasoning for trying these other then based on similar google examples. This would be my failed attempts at the first step, however if someone can manage a count on the column OperatorKey that does not include duplicate values that'd be super as well. If there's an explanation to the query as well then i might just be in heaven...  Results i get: Operator Key DateLoaded ID 402 2013-xx 8052 402 2013-xx 8053 403 2013-xx 8054 Results i want: 402 2013-xx 8052 403 2013-xx 8054 etc
I think I read the problem right, if not, just let me know. There might be a better way to do this, my sql foo isn't master level jedi.
select * from DimOperator join ( select OperatorKey, min(ID) as minid, count(oper) as counter from DimOperator group by OperatorKey ) ss on ( DimOperator.ID = ss.minid )
The first thing you need to do is get all the opers and an associated id with it, in this case I just picked the min. This will also let you get the count.
select OperatorKey, min(ID) as minid, count(OperatorKey) as counter from DimOperator group by OperatorKey
Once you have that information, you can join it back into your table to get the date loaded column and any other information that might be associated with that ID.
|
On March 20 2014 17:34 unkkz wrote:Damn i suck at SQL. Anyone that can help me out with this query? In the table DimOperator, i want non duplicate values of the column OperatorKey. Included in the results i need the DateLoaded column and the ID column. The values in ID and DateLoaded have no possibility of being a duplicate so i need only to display them so i can cross reference with another database. The problem is that i need a count of the column OperatorKey without duplicate values. I have tried this in two steps, aka getting no duplicates at first and then working a count in there(i'm a newb) Here's what i have tried so far: select distinct OperatorKey, ID, DateLoaded from DimOperator order by DateLoaded desc - Does not return unique OperatorKey, returns several of the same value. select MIN(OperatorKey) AS OperatorKey, DateLoaded from DimOperator group by OperatorKey, DateLoaded order by DateLoaded desc - Same problem as above, it does not return unique OperatorKey's. I have no real reasoning for trying these other then based on similar google examples. This would be my failed attempts at the first step, however if someone can manage a count on the column OperatorKey that does not include duplicate values that'd be super as well. If there's an explanation to the query as well then i might just be in heaven...  Results i get: Operator Key DateLoaded ID 402 2013-xx 8052 402 2013-xx 8053 403 2013-xx 8054 Results i want: 402 2013-xx 8052 403 2013-xx 8054 etc Basically what you need is undefined, since you can have multiple values of ID for every value of OperatorKey. You need to specify which of them you want in the result.
Following will give you list of unique values of OperatorKey :
SELECT DISTINCT OperatorKey FROM ...
To incorporate the other 2 columns you need, as I said, to specify how they should be determined as they are not deterministic.
One (most likely not te one you want) possibility is for example :
SELECT OperatorKey, MIN(DateLoaded), MIN(ID) FROM ... GROUP BY OperatorKey
The likely issue with that query is that the two aggregate values are not guaranteed to be from the same row of the source table.
If you are just interested in the count :
SELECT COUNT(DISTINCT OperatorKey) FROM ...
This should work, but I am not sure if it is not DB specific.
|
On March 20 2014 14:48 Manit0u wrote:Ok, I have a bit of a problem with character encoding in C#. I have this: string[] lines = File.ReadAllLines (@"path\to\file");
Then I enter the loop to parse all lines and extract substrings from them that I need. The problem I'm facing is that the file is encoded in ASCII (has to be) and I'm not quite sure how to enforce this encoding on the stream I'm getting from the file (not to mention that I want to add write to file part soon and it'll have to be in ASCII too). Do I have to change it to byte[] and make it a char array? That would be very inconvenient since I'm using quite a lot of quite long strings in there (lines are ~400 characters wide) and actually very few characters in there are using non-latin letters (which I want to preserve in my strings). Do any of you have experience with this sort of stuff?
All my experience with file encoding is in java, and I have 0 experience in C# -- so, what I say may not translate the best. It looks like though that, just like in java, there is a way to specify the encoding when you read in all the lines.
Link to some proof
Best of luck, encoding is the worst of all software development problems imo.
|
On March 20 2014 20:15 berated- wrote:Show nested quote +On March 20 2014 14:48 Manit0u wrote:Ok, I have a bit of a problem with character encoding in C#. I have this: string[] lines = File.ReadAllLines (@"path\to\file");
Then I enter the loop to parse all lines and extract substrings from them that I need. The problem I'm facing is that the file is encoded in ASCII (has to be) and I'm not quite sure how to enforce this encoding on the stream I'm getting from the file (not to mention that I want to add write to file part soon and it'll have to be in ASCII too). Do I have to change it to byte[] and make it a char array? That would be very inconvenient since I'm using quite a lot of quite long strings in there (lines are ~400 characters wide) and actually very few characters in there are using non-latin letters (which I want to preserve in my strings). Do any of you have experience with this sort of stuff? All my experience with file encoding is in java, and I have 0 experience in C# -- so, what I say may not translate the best. It looks like though that, just like in java, there is a way to specify the encoding when you read in all the lines. Link to some proofBest of luck, encoding is the worst of all software development problems imo.
Edit:
Even though the file was encoded in ASCII the Windows-1252 charset did the trick for me. Odd.
string[] lines = File.ReadAllLines (@"path\to\file", Encoding.GetEncoding (1252));
|
On March 21 2014 04:03 Manit0u wrote:Show nested quote +On March 20 2014 20:15 berated- wrote:On March 20 2014 14:48 Manit0u wrote:Ok, I have a bit of a problem with character encoding in C#. I have this: string[] lines = File.ReadAllLines (@"path\to\file");
Then I enter the loop to parse all lines and extract substrings from them that I need. The problem I'm facing is that the file is encoded in ASCII (has to be) and I'm not quite sure how to enforce this encoding on the stream I'm getting from the file (not to mention that I want to add write to file part soon and it'll have to be in ASCII too). Do I have to change it to byte[] and make it a char array? That would be very inconvenient since I'm using quite a lot of quite long strings in there (lines are ~400 characters wide) and actually very few characters in there are using non-latin letters (which I want to preserve in my strings). Do any of you have experience with this sort of stuff? All my experience with file encoding is in java, and I have 0 experience in C# -- so, what I say may not translate the best. It looks like though that, just like in java, there is a way to specify the encoding when you read in all the lines. Link to some proofBest of luck, encoding is the worst of all software development problems imo. Edit: Even though the file was encoded in ASCII the Windows-1252 charset did the trick for me. Odd. string[] lines = File.ReadAllLines (@"path\to\file", Encoding.GetEncoding (1252));
If the file was generated on windows, then it was probably always cp 1252. It's such a headache, because its so close to iso 8859-1 (latin-1) but just took some control characters and used them for fun quotation marks and such. Glad you figured it out.
Encoding is so hard because everyone in the chain has to get it right, and can possibly change it. If you email a file, if you save a file, open it in a different text editor. If you are linux then even the shell you are in can interpret the characters wrong. I cringe a bit anytime someone mentions an encoding issue.
|
Yeah, I got a file from Norway (with their special characters) created on OSX and I had to deal with it on Windows.
|
|
|
I guess that if you don't need any special accent and characters then ASCII is still the way to go. It's situational but it becomes relevant when you need to do operations on a file and refering to specific bytes. With UTF-8 you can have someone unknowingly encode it with BOM and you get 3 extra bytes in front of your file occupied by that. It can be harmful for some programs since it might cause syntax violation and parsing errors. Even on wikipedia you can read of instances where PHP outputs the BOM and it might cause your functions that handle HTTP headers to fail. Without BOM you get a regular ASCII file and most Windows editors will add a BOM to ASCII files if it's not present (causing issues).
|
On March 20 2014 18:37 Nesserev wrote:My third version is almost finished, with proper AI... I hope that I can catch up --'
I almost finished my first proper bot , it took me 3 days!
|
On March 21 2014 11:30 Manit0u wrote: I guess that if you don't need any special accent and characters then ASCII is still the way to go. It's situational but it becomes relevant when you need to do operations on a file and refering to specific bytes. With UTF-8 you can have someone unknowingly encode it with BOM and you get 3 extra bytes in front of your file occupied by that. It can be harmful for some programs since it might cause syntax violation and parsing errors. Even on wikipedia you can read of instances where PHP outputs the BOM and it might cause your functions that handle HTTP headers to fail. Without BOM you get a regular ASCII file and most Windows editors will add a BOM to ASCII files if it's not present (causing issues).
Its probably nitpicky but non utf 8 character sets does not imply ASCII. ASCII is only 7 bits, and while utf 8 and a lot of the 8 bit character sets share a backwards compatibility with ASCII by sharing the first 128 characters, they are not only 7 bits. For example, windows 1252 is an 8 bit character set and doesn't have a bom but is not ASCII either. Same for all the iso 8859 variants.
|
Quick question: How do you get an int from command line in Go? I'm trying var numArgs int = len(os.Args) var numThreads int = strconv.Atoi(os.Args[1]) fmt.Println(numThreads) but get told "multiple-value strconv.Atoi() in single-value context", which points to the strconv line. The documentation online has been pretty awful so far and I really can't find anything.
|
On March 22 2014 05:58 WarSame wrote:Quick question: How do you get an int from command line in Go? I'm trying var numArgs int = len(os.Args) var numThreads int = strconv.Atoi(os.Args[1]) fmt.Println(numThreads) but get told "multiple-value strconv.Atoi() in single-value context", which points to the strconv line. The documentation online has been pretty awful so far and I really can't find anything.
http://stackoverflow.com/questions/19531406/how-do-i-use-the-strconv-atoi-method-in-go
|
Awesome, thanks. I saw that one earlier but misunderstood what was going wrong.
|
Also signed up when I saw this, starting to make some progress (Plus set up a local autotest system which is pretty sweet, I can compile my code and test it vs every previous version I've made to see if its an improvement!)
|
Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline.
|
On March 24 2014 19:04 endy wrote: Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline.
Appcelerator Titanium. Nothing else comes close.
|
Hey guys I hope someone can help me out with some basic knowledge of Java and iterators and comparables/comparators. So I have an assignment where I need to iterate in ascending and descending order of stock portfolios and their stock shares. I'm reading data from a text file, I think I have most of that part done. Then I need to use iterable and comparables to sort the data in a certain ascending order. If someone could lead me in the right direction it would be greatly appreciated, but i'm quite stuck in this assignment so far, and so are the rest of my classmates lol -_-. Here is what I have so far:
package PortfolioMaps;
import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Objects;
class Investment implements Comparable<Investment>{ private String ticker; // unique string identifier for stocks private int numShares; private double price;
public boolean equals( Object rhs ){ return false; }
public int compareTo( Investment rhs ){ return 0; }
class Portfolio implements Comparable<Portfolio> { private String protfolioId; private double cashBalance; private List<Investment> holdings = new LinkedList<>(); @Override public int compareTo(Portfolio obj){ return 0; } } // All the portfolios owned by a single customer
class Account implements Comparable<Account>, Iterable<Portfolio> { private String accountId; private List <Portfolio> portfolios; @Override public int compareTo(Account obj){ return 0; } void addPortfolio( Portfolio obj2 ){ };
public Iterator<Portfolio> iterator(){ } } }
Don't mind the return statements, I just filled those out so I can have the methods working in order to test my program. If someone could please explain to me how the compareTo method is suppose to work alongside with the methods that implement Comparable Accounts and Iterable portfolios it would be great help! Pseudo code is fine, I am a quick learner. Thanks in advance.
|
So Comparable forces you (as you know) to implement the compareTo method. This method is used by other methods (for example Collections.sort) to determine which of 2 objects is "larger".
So lets take your Investment class and say we want to say the price of an investment is
double totalPrice = numShares*price;
and an investment is "greater" than another investment if its total price is higher than the other:
public int compareTo( Investment rhs ){ /* Find out this objects total price*/ double thisTotalPrice = this.numShares*this.price;
/* Find out rhs total price */ double rhsTotalPrice = rhs.numShares*rhs.price;
/* Return the difference (this - rhs)*/ return thisTotalPrice - rhsTotalPrice; }
+ Show Spoiler + Note that this implementation will not work as numShares and price are declared as private, so you need getters/setters to access them.
The important thing is: If this > rhs then the returned value is > 0. If this .equals(rhs) then the return value is == 0 (this is NOT enforced, however it is good practice). if this < rhs then the returned value is < 0.
If we then were to do:
ArrayList<Investment> investments = new ArrayList<Investment>(); /* ... Fill ArrayList ...*/ Collections.sort(investments);
then ArrayList<Investment>.get(0) would have the lowest total price investment (as the .sort method sorts in ascending order).
Hope this helps somewhat
|
|
|
|
|
|