Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Conversation

@rohithasrk
Copy link
Contributor

References #32. As of now, I've just added a Snapshot model and starting working on save_snapshot function.

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-2.6%) to 97.351% when pulling 74c94c5 on rohithasrk:topology-history into ba51a6f on netjson:master.

"""
Saves the snapshot of topology
"""
Snapshot = self.snapshot_model
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snapshot = will make flake8 complain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't get you @nemesisdesign. There are no errors in the travis as of now

Copy link
Member

@nemesifier nemesifier Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, I don't know why I was tricked by my memory. Some code analysis tool complain if you declare a CamelCase variables, but not the default flake8 configuration, ignore this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress! 👍

After addressing my inline comments start adding tests and API

s.data = self.json()
else:
s = Snapshot(topology=self, data=self.json())
s.save()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not:

date = datetime.now().date()
options = dict(topology=self, date=date)
try:
    s = Snapshot.objects.get(**options)
else:
    s = Snapshot(**options)
s.data = self.json()
s.save()

Copy link
Contributor Author

@rohithasrk rohithasrk Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better.

- save snapshots of topoogies
- logs failures
"""
queryset = cls.objects.all()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to:

queryset = cls.objects.filter(published=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-3.7%) to 96.284% when pulling 07b1e73 on rohithasrk:topology-history into 7ea174a on netjson:master.

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-4.3%) to 95.666% when pulling cc07515 on rohithasrk:topology-history into 7ea174a on netjson:master.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohithasrk you have improved a lot but you need to start writing tests sooner in the process to become a great developer. See my inline comments and then please start adding tests


def get(self, request, pk, format=None):
topology = get_object_or_404(self.topology_model, pk)
date = request.query_params.get('date')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write a test in which you supply a rubbish date here, make it fail and then find a fix (great occasion to learn TDD)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I get it 😄


def post(self, request, pk, format=None):
topology = get_object_or_404(self.model, pk, strategy='receive')
topology = get_object_or_404(self.topology_model, pk, strategy='receive')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand: why do we need to change this line? I think we can keep self.model because we don't need to handle different models in this view

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True that. I thought it would just make it a little more uniform.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a general rule, never change lines which are working fine and do not need to be changed, unless you have a very valid reason to do so

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-1.9%) to 98.089% when pulling 57227ab on rohithasrk:topology-history into 7ea174a on netjson:master.

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-0.8%) to 99.204% when pulling 2e32eed on rohithasrk:topology-history into 7ea174a on netjson:master.

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling c6905e2 on rohithasrk:topology-history into 7ea174a on netjson:master.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohithasrk great progress 👍 see my inline comments, then proceed with the remaining tasks

return '/api/receive/{0}/?key=test'.format(t.pk)

def _set_receive(self, topology_model):
t = topology_model.objects.first()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could make this a property by prepending @property to it, then you can call self.snapshot_url

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes. Will do it

t.expiration_time = 0
t.save()

def snapshot_date(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, it makes sense to use the @property decorator here too

@coveralls
Copy link

coveralls commented Jul 26, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 454b690 on rohithasrk:topology-history into 7ea174a on netjson:master.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohithasrk good progress 👍

what's next?

@coveralls
Copy link

coveralls commented Jul 27, 2017

Coverage Status

Coverage decreased (-0.8%) to 99.219% when pulling c75c405 on rohithasrk:topology-history into 7ea174a on netjson:master.

@coveralls
Copy link

coveralls commented Aug 4, 2017

Coverage Status

Coverage decreased (-1.7%) to 98.3% when pulling 91d8b19 on rohithasrk:topology-history into 7ea174a on netjson:master.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 great progress @rohithasrk, see my inline comments.

PS: here's more feedback after having tested the changes.

  • is the CSS of the datepicker widget missing or what? I get an unstyled widget in my test env
  • put the date field in an overlay using the same CSS classes used for the upper right and left overlay and adapt the style so
  • try to set the default date to the current date and edit the javascript so that if the date set is equal to the current date the date parameter sent to the API is empty, that way we get the latest data in the default case but for users it will be easier to understand they can change the date; any other small usability improvement is appreciated!


def visualize_view(self, request, pk):
topology = get_object_or_404(self.model, pk)
api_url = reverse('network_graph', args=[pk])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change 👍

}
date = date.join('-');
graph_url = $('.switcher').attr('graph-url')+'?date='+date;
console.log(graph_url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you forgot this console.log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. My bad

@coveralls
Copy link

coveralls commented Aug 9, 2017

Coverage Status

Coverage decreased (-1.7%) to 98.302% when pulling a9da46e on rohithasrk:topology-history into 7ea174a on netjson:master.

@coveralls
Copy link

coveralls commented Aug 9, 2017

Coverage Status

Coverage decreased (-1.7%) to 98.302% when pulling 0f23c09 on rohithasrk:topology-history into 7ea174a on netjson:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.7%) to 98.302% when pulling 3633e40 on rohithasrk:topology-history into 7ea174a on netjson:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.7%) to 98.302% when pulling 3633e40 on rohithasrk:topology-history into 7ea174a on netjson:master.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you added the missing CSS yet?

<p><span class="link down">&nbsp;</span>link down</p>
</div>
<div class="switcher" graph-url='{{graph_url}}'>
<label for="datepicker"> Date</label><input type="text" id="datepicker">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the space before the word Date necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Missed it.

@coveralls
Copy link

coveralls commented Aug 9, 2017

Coverage Status

Coverage decreased (-1.7%) to 98.302% when pulling 8273ecd on rohithasrk:topology-history into 7ea174a on netjson:master.

@coveralls
Copy link

coveralls commented Aug 14, 2017

Coverage Status

Coverage decreased (-2.0%) to 98.006% when pulling af674ba on rohithasrk:topology-history into 7ea174a on netjson:master.

@coveralls
Copy link

coveralls commented Aug 14, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling a69da2d on rohithasrk:topology-history into 614d11b on netjson:master.

@coveralls
Copy link

coveralls commented Aug 15, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling d13cca5 on rohithasrk:topology-history into 614d11b on netjson:master.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great! You are almost there, see my inline comments

visualize_url = $('.visualizelink').attr('data-url');

var d = new Date(),
month = d.getMonth()+1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to d.getMonth() + 1

var d = new Date(),
month = d.getMonth()+1,
day = d.getDate(),
default_date = (month<10? '0':'') + month + '/' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to month < 10 ? '0' : ''

month = d.getMonth()+1,
day = d.getDate(),
default_date = (month<10? '0':'') + month + '/' +
(day<10? '0':'') + day + '/' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add spaces between operands, eg: day < 10 ? '0' : ''

date[2] = x;
}
date = date.join('-');
graph_url = $('.switcher').attr('graph-url')+'?date='+date;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, here separate string operands and plus signs with spaces

error(function(xhr) {
if (xhr.status == 400) {
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this section? can this situation be triggered by the user? If yes, add an alert with some text message, otherwise remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This will be triggered when a date ahead is chosen. So yes. Will add an alert

current_date = d.getFullYear() + '-' +
(month<10? '0':'') + month + '-' +
(day<10? '0':'') + day;
$('#submit').click(function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of the submit event, can you use the change event of the date input? It would be more usable

@nemesifier
Copy link
Member

PS: to completely avoid the risk of breaking existing instances, this feature should be released in the 0.4.0 version

@coveralls
Copy link

coveralls commented Aug 18, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 6811506 on rohithasrk:topology-history into 614d11b on netjson:master.

@coveralls
Copy link

coveralls commented Aug 18, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 199669d on rohithasrk:topology-history into 614d11b on netjson:master.

@coveralls
Copy link

coveralls commented Aug 18, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 649e67b on rohithasrk:topology-history into a2c6e29 on netjson:master.

@rohithasrk rohithasrk changed the title [WIP] Topology history feature Topology history feature Aug 18, 2017
@nemesifier
Copy link
Member

@rohithasrk I think one point is still missing:

  • put the date field in an overlay using the same CSS classes used for the upper right and left overlay and adapt the style so

@coveralls
Copy link

coveralls commented Aug 22, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling c16daef on rohithasrk:topology-history into a2c6e29 on netjson:master.

@coveralls
Copy link

coveralls commented Aug 22, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling cd4cc17 on rohithasrk:topology-history into a2c6e29 on netjson:master.

@nemesifier nemesifier changed the title Topology history feature [feature] Topology history Aug 23, 2017
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohithasrk 👍 great work. I will rebase&merge this and add a small improvement to the UI

@nemesifier nemesifier merged commit c6b3cdc into openwisp:master Aug 23, 2017
@rohithasrk rohithasrk deleted the topology-history branch August 27, 2017 22:44
@acoul
Copy link
Contributor

acoul commented Apr 22, 2019

Greetings from AWMN

Silly question: How can I use the snapshot feature?

It doesn't appear in the admin panel as an option, while issuing a manage.py save_snapshot on a daily cron job doesn't auto-magically populate the history calendar.

@nemesifier
Copy link
Member

@acoul are you using the latest version? A calendar show automatically show up, eg: https://openwisp.nnxx.ninux.org/topology/topology/36d5ba3e-1364-49d2-9e29-1f6dceb7cbbb/

@acoul
Copy link
Contributor

acoul commented Apr 22, 2019

yes using latest git version.

every night @ 11 a cron executes a "manage.py save_snapshot "
a cron job "manage.py update_topology" runs every 30 minutes

when clicking on a previous date at the calendar I get a "no snapshot found for this date" message

Edit: it's working just fine. sorry for the noise

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants