-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John D
committed
Apr 10, 2016
1 parent
02a9733
commit fa84791
Showing
13 changed files
with
13,027 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Npgsql; | ||
|
||
|
||
namespace tribe | ||
{ | ||
class BabySitter | ||
{ | ||
public static void KickUsAlong() | ||
{ | ||
MMDB.MakeSureDBIsOpen(); | ||
|
||
HashSet<Int32> optedIn = FData.IDsInTheyReadMeFData(FData.GetFData("ljfinder", true)); | ||
optedIn.UnionWith(FData.IDsInTheyReadMeFData(FData.GetFData("ljmindmap", true))); | ||
|
||
DateTime TwoK = new DateTime(2000, 1, 1); | ||
int weeks = (int)(DateTime.Now.Subtract(TwoK).Days / 7.02); | ||
int months = (int)(DateTime.Now.Subtract(TwoK).Days / 30.4); | ||
|
||
string sqlset = ""; | ||
foreach (var dude in optedIn) | ||
sqlset += dude.ToString() + ","; | ||
sqlset = sqlset.Substring(0, sqlset.Length - 1); | ||
|
||
// any opt-ins who haven't been reached this week or last, for whom lastpublishedmonth is not this month, whose status is 'L' or 'N' or 'S'? | ||
// set them to status 'S' and set statuschanged=null. If any rows are effected, then I don't email anybody this time! | ||
// HEY fuck's sake i'm changing the value of week because emailing someone i emailed last week is too fucking much. | ||
weeks = weeks - 1; | ||
|
||
// if mm lastpublishmonth isn't this month, is it status 'L' or 'N' ? | ||
// if so, then set it to status 'S' and set statuschanged=null, | ||
// and postpone any talk of notifications. | ||
|
||
NpgsqlCommand cmd = new NpgsqlCommand(string.Format( | ||
// "select count(*) from nameidmap where id in ({0}) and inbox_hit_week < {1} and lastpublishedmonth < {2} and status in ('L', 'N') ;", | ||
"select count(*) from nameidmap where id in ({0}) and inbox_hit_week < {1} and lastpublishedmonth < {2} and status in ('L', 'N', 'S') ;", | ||
sqlset, weeks, months), MMDB.DBConnection); | ||
|
||
NpgsqlDataReader myReader = cmd.ExecuteReader(); | ||
myReader.Read(); | ||
Int64? iResult = MMDB.MaybeNullInt64(myReader, 0); | ||
myReader.Close(); | ||
|
||
if (0 == iResult) | ||
{ | ||
// go ahead and notify! | ||
// lots of optedIn are excluded because i've reached 'em too recently. | ||
HashSet<Int32> eligible = new HashSet<Int32>(); | ||
cmd = new NpgsqlCommand(string.Format( | ||
"select id from nameidmap where id in ({0}) and inbox_hit_week < {1} ;", | ||
sqlset, weeks, months), MMDB.DBConnection); | ||
myReader = cmd.ExecuteReader(); | ||
while (myReader.Read()) | ||
{ | ||
eligible.Add(myReader.GetInt32(0)); | ||
} | ||
myReader.Close(); | ||
|
||
// eligible.Add(IDMap.NameToID("eclipsenacht")); | ||
|
||
// fuck eligible we're testing mcfnord | ||
// eligible.Clear(); | ||
// eligible.Add(IDMap.NameToID("mcfnord")); | ||
|
||
Radar2010.RefreshBasedOnRadarSignals_AndPublish(eligible); | ||
return; | ||
} | ||
|
||
Console.WriteLine("Waiting in {0} dudes.", iResult); | ||
|
||
MMDB.ExecuteNonQuery(string.Format( | ||
"update nameidmap set status='S', statuschanged=null where id in ({0}) and inbox_hit_week < {1} and lastpublishedmonth < {2} and status in ('L', 'N', 'S') ;", | ||
sqlset, weeks, months)); | ||
|
||
// kick along. | ||
} | ||
} | ||
} | ||
|
||
|
||
/* | ||
while (myReader.Read()) | ||
eligible.Add(myReader.GetInt32(0)); | ||
myReader.Close(); | ||
// for these boner eligible-for-contact jerks, is the mindmap fresh? | ||
// HashSet<Int32> current = new HashSet<Int32) () ; | ||
bool fready = true; | ||
foreach (var dude in eligible) | ||
{ | ||
// if i never published this dude in this month, | ||
// if( false == MMDB.QueryFindsRow(string.Format("select * from nameidmap where id={0} and lastpublishedmonth = {1} LIMIT 1 ;", dude, months ))) | ||
if (true == MMDB.QueryFindsRow(string.Format("select * from nameidmap where id={0} and status in ('L', 'N') and lastpublishedmonth < {1} LIMIT 1 ;", dude, months))) | ||
{ | ||
// then i need to publish that dude in this month | ||
Console.WriteLine(IDMap.IDToName(dude) + " not ready."); | ||
fready = false; // we aren't fready to launch our nut. | ||
// and push it through. which means... making statusdate null. and what statuses get pushed back to scraped? | ||
MMDB.ExecuteNonQuery(string.Format("update nameidmap set statuschanged = null where id={0} ;", dude)) ; // null-hammered, absolutely! | ||
// and if it's NULL (queued) or already calculated, we make it scraped with its fancy null statuschanged refreshed null null null | ||
if (MMDB.QueryFindsRow(string.Format("select * from nameidmap where (status='N' or status='L') and lastpublishedmonth < {1} and id={0} LIMIT 1 ;", dude, months))) | ||
MMDB.ExecuteNonQuery(string.Format("update nameidmap set status='S' where id={0};", dude)); | ||
} | ||
} | ||
if (false == fready) | ||
return; // no notifications until we're all ready. | ||
// if i haven't reached 'em too recently, are tehy ready? if they aren't ready, print them, and kick them with a null. | ||
// if i have contacted any party this week or last, i remove them from consideration. | ||
// WAIT A SECOND AREN'T A LOT OF OPTED IN PEOPLE REMOVED FROM CONSIDERATION, THEY MUST BE ALL CLEAR. | ||
// babysitter only calls me once mm is fresh enough and it's cool to notify every ... | ||
// ugh... crashing. | ||
// i only wanna notify when status is 'L' | ||
Debug.Assert(false);// crazy how this critical part seems outta control. | ||
// let's re-design it, writing the sql in advance. | ||
// test the inbox_hit_week is too low. | ||
// if mm lastpublishmonth isn't this month, is it status 'L' or 'N' ? | ||
// if so, then set it to status 'S' and set statuschanged=null, | ||
// and postpone any talk of notifications. | ||
foreach (var dude in eligible) | ||
{ | ||
// maybe i need to carve eligible into a new array. | ||
// if (true == MMDB.QueryFindsRow(string.Format("select * from nameidmap where id={0} and status='L' LIMIT 1 ;", dude))) | ||
// { | ||
// System.Diagnostics.Debug.Assert(eligible.Count > 0); // if this is zero, maybe i should publish to fresh-mindmap (this month) people who i haven't hit ever in the inbox, by high apy first. ;) | ||
Radar2010.RefreshBasedOnRadarSignals_AndPublish(eligible); | ||
// } | ||
} | ||
// note week-of-notification in radar2010 so i can exclude it (and the week before it) here. | ||
} | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
//Copyright (c) 2007-2008 Henrik Schröder, Oliver Kofoed Pedersen | ||
|
||
//Permission is hereby granted, free of charge, to any person | ||
//obtaining a copy of this software and associated documentation | ||
//files (the "Software"), to deal in the Software without | ||
//restriction, including without limitation the rights to use, | ||
//copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
//copies of the Software, and to permit persons to whom the | ||
//Software is furnished to do so, subject to the following | ||
//conditions: | ||
|
||
//The above copyright notice and this permission notice shall be | ||
//included in all copies or substantial portions of the Software. | ||
|
||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
//EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
//OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
//NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
//HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
//WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
//FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
//OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using System; | ||
using System.Security.Cryptography; | ||
|
||
namespace BeIT.MemCached | ||
{ | ||
/// <summary> | ||
/// Fowler-Noll-Vo hash, variant 1, 32-bit version. | ||
/// http://www.isthe.com/chongo/tech/comp/fnv/ | ||
/// </summary> | ||
public class FNV1_32 : HashAlgorithm | ||
{ | ||
private static readonly uint FNV_prime = 16777619; | ||
private static readonly uint offset_basis = 2166136261; | ||
|
||
protected uint hash; | ||
|
||
public FNV1_32() { | ||
HashSizeValue = 32; | ||
} | ||
|
||
public override void Initialize() { | ||
hash = offset_basis; | ||
} | ||
|
||
protected override void HashCore(byte[] array, int ibStart, int cbSize) { | ||
int length = ibStart + cbSize; | ||
for (int i = ibStart; i < length; i++) { | ||
hash = (hash * FNV_prime)^array[i]; | ||
} | ||
} | ||
|
||
protected override byte[] HashFinal() { | ||
return BitConverter.GetBytes(hash); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Fowler-Noll-Vo hash, variant 1a, 32-bit version. | ||
/// http://www.isthe.com/chongo/tech/comp/fnv/ | ||
/// </summary> | ||
public class FNV1a_32 : HashAlgorithm | ||
{ | ||
private static readonly uint FNV_prime = 16777619; | ||
private static readonly uint offset_basis = 2166136261; | ||
|
||
protected uint hash; | ||
|
||
public FNV1a_32() { | ||
HashSizeValue = 32; | ||
} | ||
|
||
public override void Initialize() { | ||
hash = offset_basis; | ||
} | ||
|
||
protected override void HashCore(byte[] array, int ibStart, int cbSize) { | ||
int length = ibStart + cbSize; | ||
for (int i = ibStart; i < length; i++) { | ||
hash = (hash^array[i]) * FNV_prime; | ||
} | ||
} | ||
|
||
protected override byte[] HashFinal() { | ||
return BitConverter.GetBytes(hash); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Modified Fowler-Noll-Vo hash, 32-bit version. | ||
/// http://home.comcast.net/~bretm/hash/6.html | ||
/// </summary> | ||
public class ModifiedFNV1_32 : FNV1_32 | ||
{ | ||
protected override byte[] HashFinal() { | ||
hash += hash << 13; | ||
hash ^= hash >> 7; | ||
hash += hash << 3; | ||
hash ^= hash >> 17; | ||
hash += hash << 5; | ||
return BitConverter.GetBytes(hash); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//Copyright (c) 2007-2008 Henrik Schröder, Oliver Kofoed Pedersen | ||
|
||
//Permission is hereby granted, free of charge, to any person | ||
//obtaining a copy of this software and associated documentation | ||
//files (the "Software"), to deal in the Software without | ||
//restriction, including without limitation the rights to use, | ||
//copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
//copies of the Software, and to permit persons to whom the | ||
//Software is furnished to do so, subject to the following | ||
//conditions: | ||
|
||
//The above copyright notice and this permission notice shall be | ||
//included in all copies or substantial portions of the Software. | ||
|
||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
//EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
//OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
//NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
//HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
//WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
//FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
//OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using System; | ||
|
||
namespace BeIT.MemCached { | ||
internal class LogAdapter { | ||
public static LogAdapter GetLogger(Type type) { | ||
return new LogAdapter(type); | ||
} | ||
|
||
public static LogAdapter GetLogger(string name) { | ||
return new LogAdapter(name); | ||
} | ||
|
||
/* | ||
* The problem with logging on the .Net platform is that there is no common logging framework, and | ||
* everyone seems to have their own favorite. We wanted this project to compile straight away | ||
* without external dependencies, and we want you to be able to embed it directly into your code, | ||
* without having to add references to some other logging framework. | ||
* | ||
* Therefore, the MemcachedClient code uses this LogAdapter to add flexible logging. | ||
* By default, it is implemented as simple console logging. | ||
* | ||
* If you are using log4net, simply comment out the console logging code, uncomment the log4net code, | ||
* add the using statement, and make sure your project references log4net. | ||
* | ||
* If you are using some other logging framework, feel free to implement your own version of this LogAdapter. | ||
*/ | ||
|
||
//Console Implementation | ||
private string loggerName; | ||
private LogAdapter(string name) { loggerName = name; } | ||
private LogAdapter(Type type) { loggerName = type.FullName; } | ||
public void Debug(string message) { Console.Out.WriteLine(DateTime.Now + " DEBUG " + loggerName + " - " + message); } | ||
public void Info(string message) { Console.Out.WriteLine(DateTime.Now + " INFO " + loggerName + " - " + message); } | ||
public void Warn(string message) { Console.Out.WriteLine(DateTime.Now + " WARN " + loggerName + " - " + message); } | ||
public void Error(string message) { Console.Out.WriteLine(DateTime.Now + " ERROR " + loggerName + " - " + message); } | ||
public void Fatal(string message) { Console.Out.WriteLine(DateTime.Now + " FATAL " + loggerName + " - " + message); } | ||
public void Debug(string message, Exception e) { Console.Out.WriteLine(DateTime.Now + " DEBUG " + loggerName + " - " + message + "\n" + e.Message + "\n" + e.StackTrace); } | ||
public void Info(string message, Exception e) { Console.Out.WriteLine(DateTime.Now + " INFO " + loggerName + " - " + message + "\n" + e.Message + "\n" + e.StackTrace); } | ||
public void Warn(string message, Exception e) { Console.Out.WriteLine(DateTime.Now + " WARN " + loggerName + " - " + message + "\n" + e.Message + "\n" + e.StackTrace); } | ||
public void Error(string message, Exception e) { Console.Out.WriteLine(DateTime.Now + " ERROR " + loggerName + " - " + message + "\n" + e.Message + "\n" + e.StackTrace); } | ||
public void Fatal(string message, Exception e) { Console.Out.WriteLine(DateTime.Now + " FATAL " + loggerName + " - " + message + "\n" + e.Message + "\n" + e.StackTrace); } | ||
|
||
//Empty logging Implementation | ||
/* | ||
public void Debug(string message) {} | ||
public void Info(string message) { } | ||
public void Warn(string message) { } | ||
public void Error(string message) { } | ||
public void Fatal(string message) { } | ||
public void Debug(string message, Exception e) { } | ||
public void Info(string message, Exception e) { } | ||
public void Warn(string message, Exception e) { } | ||
public void Error(string message, Exception e) { } | ||
public void Fatal(string message, Exception e) { } | ||
*/ | ||
|
||
//Log4net Implementation | ||
/* | ||
private log4net.ILog logger; | ||
private LogAdapter(string name) { logger = log4net.LogManager.GetLogger(name); } | ||
private LogAdapter(Type type) { logger = log4net.LogManager.GetLogger(type); } | ||
public void Debug(string message) { logger.Debug(message); } | ||
public void Info(string message) { logger.Info(message); } | ||
public void Warn(string message) { logger.Warn(message); } | ||
public void Error(string message) { logger.Error(message); } | ||
public void Fatal(string message) { logger.Fatal(message); } | ||
public void Debug(string message, Exception e) { logger.Debug(message, e); } | ||
public void Info(string message, Exception e) { logger.Info(message, e); } | ||
public void Warn(string message, Exception e) { logger.Warn(message, e); } | ||
public void Error(string message, Exception e) { logger.Error(message, e); } | ||
public void Fatal(string message, Exception e) { logger.Fatal(message, e); } | ||
*/ | ||
} | ||
} |
Oops, something went wrong.