The first thing to do is make sure you get enough sleep. This is by far the most important step to doing well on tests, getting your homework done, and avoiding procrastination. If you are still doing work at midnight, take a shower and just go to bed. You're not going to be productive if you're sleep-deprived so there's no reason to keep trying past midnight.
I also recommend making a schedule for yourself -- outline an approximate time that each portion of work will take, and figure out a work schedule (with built-in 10-15 minute breaks every 1.5-2 hours to keep you on track). It can also be helpful to study with a tutor, who you can get access to at https://stuyarista.org.
If you're looking for more serious emotional help, you can always talk to your guidance counselor or Angel Colon, head of the SPARK department. His office can be found in room 726.