This file contains hidden or 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
@time_analysis_controller.route('/time/question/track', methods=['POST']) | |
@login_required | |
def update_question_time(): | |
""" | |
Update the time spent on a question using the 'heartbeat' signal. | |
The question attempt is fetched based on the current user and question id. | |
And a random number between 1 and 5 is added to the time spent. | |
The update is added to the total time spent for that question attempt | |
:return: 404 if the question attempt didnt exist, 200 if time was successfully updated |
This file contains hidden or 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
def get_highest_score(test_id): | |
test_attempts = db.session.query(TestAttempt).filter_by(test_id=test_id) | |
scores = [] | |
if test_attempts.count() < 1: | |
return {'max_score': 0} | |
for each in test_attempts: | |
user_id = each.user_id | |
test_id = each.test_id | |
if each.is_complete: | |
k = get_college_test_attempt_score(test_id, user_id)['score'] |
This file contains hidden or 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
def get_highest_score(test_id): | |
test_attempts = db.session.query(TestAttempt).filter_by(test_id=test_id) | |
scores = [] | |
if test_attempts.count() < 1: | |
return {'max_score': 0} | |
for each in test_attempts: | |
user_id = each.user_id | |
test_id = each.test_id | |
if each.is_complete: | |
k = get_college_test_attempt_score(test_id, user_id)['score'] |
This file contains hidden or 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
import React, {PropTypes, Component} from 'react'; | |
import * as action from '../actions/action'; | |
import $ from 'jquery'; | |
import {connect} from 'react-redux'; | |
import {bindActionCreators} from 'redux'; | |
import UserPanel from './UserPanel'; | |
import Navlink from './Navlink'; | |
import Footer from './Footer'; | |
import UserMenu from './UserMenu'; |
This file contains hidden or 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
folder_dataset_test = dset.ImageFolder(root=Config.testing_dir) | |
siamese_dataset = SiameseNetworkDataset(imageFolderDataset=folder_dataset_test, | |
transform=transforms.Compose([transforms.Scale((100,100)), | |
transforms.ToTensor() | |
]) | |
,should_invert=False) | |
test_dataloader = DataLoader(siamese_dataset,num_workers=6,batch_size=1,shuffle=True) | |
dataiter = iter(test_dataloader) | |
x0,_,_ = next(dataiter) |
This file contains hidden or 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
net = SiameseNetwork().cuda() | |
criterion = ContrastiveLoss() | |
optimizer = optim.Adam(net.parameters(),lr = 0.0005 ) | |
counter = [] | |
loss_history = [] | |
iteration_number= 0 | |
for epoch in range(0,Config.train_number_epochs): | |
for i, data in enumerate(train_dataloader,0): |
This file contains hidden or 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
class SiameseNetworkDataset(Dataset): | |
def __init__(self,imageFolderDataset,transform=None,should_invert=True): | |
self.imageFolderDataset = imageFolderDataset | |
self.transform = transform | |
self.should_invert = should_invert | |
def __getitem__(self,index): | |
img0_tuple = random.choice(self.imageFolderDataset.imgs) | |
#we need to make sure approx 50% of images are in the same class |
This file contains hidden or 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
class ContrastiveLoss(torch.nn.Module): | |
""" | |
Contrastive loss function. | |
Based on: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf | |
""" | |
def __init__(self, margin=2.0): | |
super(ContrastiveLoss, self).__init__() | |
self.margin = margin |
This file contains hidden or 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
class SiameseNetwork(nn.Module): | |
def __init__(self): | |
super(SiameseNetwork, self).__init__() | |
self.cnn1 = nn.Sequential( | |
nn.ReflectionPad2d(1), | |
nn.Conv2d(1, 4, kernel_size=3), | |
nn.ReLU(inplace=True), | |
nn.BatchNorm2d(4), | |
nn.Dropout2d(p=.2), | |
This file contains hidden or 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
import java.time.Instant; | |
public class WarpCLI { | |
private static final long START_EPOCH = 885709023L; | |
public WarpCLI() {} | |
public static void main(String[] paramArrayOfString) { Instant localInstant1 = Instant.now(); | |
Instant localInstant2 = Instant.ofEpochSecond(885709023L); | |
Instant localInstant3 = localInstant2.plus(1L, java.time.temporal.ChronoUnit.DAYS); |